【发布时间】:2019-08-05 07:12:34
【问题描述】:
public class Service
{
public int Id { get; set; }
public string Title { get; set; }
}
public class Store
{
public int Id { get; set; }
public virtual Service Service { get; set; }
}
public class Product
{
public int Id { get; set; }
public virtual Service Service { get; set; }
}
public class Operation
{
public int Id { get; set; }
public virtual Service Service { get; set; }
}
我有一个在其他实体中使用的Service 实体。我想获取所有使用Service 的实体。
我的意思是获取使用 Service 的实体列表,如下所示:
public virtual Service Service { get; set; }
在实体框架中可以吗?
【问题讨论】:
-
为什么不将其他实体作为导航属性添加到
Service? -
因为没关系。我不想要数据。我只想获取所有使用 Service 的实体。使用服务的“dbset”列表
-
嗯,现在的问题根本不在于实体框架。你寻求的是反思。
-
@ilkerkaran 可能不是真的,请参阅下面的评论。
-
@GertArnold,实际上他可以访问上下文属性并枚举它们的类型等。实体框架只是OP询问类关系和访问类型时的一个细节示例。
标签: c# entity-framework relationship