- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我搜索像这样的“列表”时 DbSet<T>.Where(predicate)
我可以加.Include("xxx")
但这不适用于单个对象。
我不知道如何让 EF 加载 virtual
Icollection<T>
属性,调用时 DbSet<T>.Find(id)
最佳答案
使用当前的 API,您无法使用 Find 进行预加载方法:
来自 P erformance Considerations for Entity Framework 5
What you have to consider when using the Find method is:
...
Also, keep in mind that Find only returns the entity you are looking for and it does not automatically loads its associated entities if they are not already in the object cache. If you need to retrieve associated entities, you can use a query by key with eager loading.
所以最接近的是您可以获得的查询,例如使用 SingleOrDefault
dbSet.Include("xxx").SingleOrDefault(i => i.Id == id)
或者你可以显式地load the related entities找到之后:
using (var context = new Db())
{
var entity = context.SomeSet.Find(id);
context.Entry(entity).Collection(p => p.SomeCollection).Load();
}
关于c# - 调用 DBSet<T>.Find(id) 时,如何使 EF Code First 加载 "ICollection"属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12489878/
我可以将我的 DbSet 从 DbSet 获取到 DbSet 吗? public IQueryable GetData() where T : class, IData { var
版本信息: 我正在使用 C# 4.5、Entity Framework 6.0 和 MEF。 代码和单元测试 我创建了一个测试项目来解释这个问题: https://skydrive.live.com/
在 Entity Framework Code First 中,当我声明实体时,我必须使用 DbSet<> 类型的属性。例如: public DbSet Products { get; set; }
我们目前正在集成一个为我们提供数据的外部系统。该系统包含有关客户许可证及其更新时间的信息。每个许可证或作为模型调用的 TPCase 可以有多个更新周期 TPRenewalCycle。然后,客户可以在我
我的问题是我正在使用的系统期望数据为 IQuearable entityframework 给我的数据为 IQueryable 这是我需要实现的接口(interface): public IQuery
我一直在使用 Add() 并遇到一个问题,即当 Add 一个子实体时,父实体在数据库中被复制。使用 Attach() 解决了这个问题,但我想知道为什么而不是盲目地摸索。 最佳答案 好吧,当您使用 At
我想通过实体模型(使用模型优先方法创建)将我的 DataGridView 控件数据绑定(bind)到数据库,我正在使用 EF 5.0、.NET 4.5 和 winforms 我的绑定(bind)组织如
Entity Framework 6中有多种添加/删除实体的方法,例如添加实体,我们可以使用:- b.Students.Add(student); db.SaveChanges(); 或 db.Ent
我想要一个字符串列表,并使用 EF-CodeFirst 将它们保存到数据库或从数据库加载它们。这是我的 DbContext 类: public class KeysDbContext : DbCont
我有两种类型的实体:员工实体和办公室实体,两者之间存在一对多关系,因此一个办公室有很多员工。对于 EF,在上下文文件中为每个实体创建一个 DbSet: public DbSet Offices { g
我的 Entity Framework 上下文: public class MyContext : DbContext { public DbSet Companies { get; set;
我正在尝试在 mac os webapi 上使用 asp.net core 2.1 调用 View 或存储过程。 using System; using System.Linq; using Auth
假设我有两个不同的类(class)。它们共享一些属性,但也有一些单独的属性。 public class A { // Shared properties public int Id {
这个问题在这里已经有了答案: 9年前关闭。 Possible Duplicate: ObjectSet.Context vs DbSet 首先从 EF 代码中的 DbSet,有没有办法引用父 DbCo
DbSet.Add() 将单个实体添加到 DbSet。但是没有 DbSet.AddRange() 来添加实体列表。有没有一种方法可以直接从 EF 调用,允许我添加实体列表?如果没有,EF不提供这种方法
我有通用的存储库模式的基本实现 IRepository其中包含 Add , Remove , Find等,我有更精确的存储库,例如 IActorRepository和 IFilmRepository源
我有一个包含许多 DbSet 的上下文。其中一些 DbSet 实现了一个称为 IActivity 的接口(interface),该接口(interface)包含许多常用字段,例如 TimeReceiv
(我这里使用的是 EF6)假设我有一个抽象类: public abstract class MyContext : DbContext 让我们使用它: public class MyTestConte
我想获取一个 DbSet,其中包含我存储在变量中的类名。 我试过这段代码: string name = "ParosLineas"; var dbset = (System.Data.Entity.D
我见过人们包装 DbSet在Lazy类别:Lazy> .我只能在互联网上找到另一个做 this 的人. 这样做的效果是什么? 最佳答案 EntityFramework 在内部避免做一些它需要在启动时做
我是一名优秀的程序员,十分优秀!