Ich muss die verwandte Navigationseigenschaft einer FK-Eigenschaft finden.Entity Framework: Ähnliche Navigationseigenschaft von FK-Eigenschaft finden
Das ist mein Modell ist:
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; }
}
Jetzt will ich etwas schreiben: erste
var context = new BloggingContext();
var navigationProperty = GetNavigationProperty(context, typeof(Post), "BlogId"); // returns "Blog"
Ich verwende EF 6.2 mit Code.
Vielen Dank für jede Hilfe!