2017-12-06 3 views
-1

FKプロパティの関連ナビゲーションプロパティを検索する必要があります。Entity Framework:FKプロパティによる関連ナビゲーションプロパティの検索

は、これは私のモデルである:私は最初のコードでEF 6.2を使用してい

var context = new BloggingContext(); 
var navigationProperty = GetNavigationProperty(context, typeof(Post), "BlogId"); // returns "Blog" 

public class Blog 
{ 
    public int BlogId { get; set; } 
    public string Url { get; set; } 

    public virtual ICollection<Post> Posts { get; set; } 
} 

public class Post 
{ 
    public int PostId { get; set; } 
    public string Title { get; set; } 
    public string Body { get; set; } 

    public int BlogId { get; set; } 
    public virtual Blog Blog { get; set; } 
} 

public class BloggingContext : DbContext 
{ 
    public DbSet<Blog> Blogs { get; set; } 
    public DbSet<Post> Posts { get; set; } 
} 

は今、私はこのような何かを書きたいです。

ありがとうございました!

答えて

0

多くの研究の後、私はantリソースやサンプルの検索方法を見つけられませんでしたが、次のコードで一時的な解決策を見つけました。最適な方法か例外があるかわかりませんそれと。

誰かがより良い解決策を持っていれば、私は感謝します。

関連する問題