Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 用于查询实体框架上下文的API';s型?_C#_Entity Framework_Entity Data Model - Fatal编程技术网

C# 用于查询实体框架上下文的API';s型?

C# 用于查询实体框架上下文的API';s型?,c#,entity-framework,entity-data-model,C#,Entity Framework,Entity Data Model,我首先使用EF代码,我想通过编程识别哪些属性是导航属性,哪些是外键,哪些是ID。例如,在这个经典的订单/项目示例中 public class Order { public int Id { get; set; } public virtual ICollection<OrderItem> Items { get; set; } public class OrderItem { public int Id { get; set; } public in

我首先使用EF代码,我想通过编程识别哪些属性是导航属性,哪些是外键,哪些是ID。例如,在这个经典的订单/项目示例中

public class Order
{
    public int Id { get; set; }
    public virtual ICollection<OrderItem> Items { get; set;
}

public class OrderItem
{
    public int Id { get; set; }
    public int OrderId { get; set; }
    public Order Order { get; set; }
    public int ProductCount { get; set; }
}

EF中是否存在这样的东西?

您需要下拉到ObjectContext,然后您可以通过探索获取有关模型的所有信息。 这个API及其背后的整个模型非常可怕(导航属性是最复杂的)

此线程包含一个帮助您入门的示例:

 var model = CreateModelFor(salesContext);
 var foreignKeys = model.ForeignKeysFor(typeof(Order)); // ["OrderId"]
 var navigationProperties = model.NavigationPropertiesFor(typeof(Order)) // [`Order`]