次のモデル例(これはofficial ASP.NET siteから取得)では、Blogs
(親)テーブルとPosts
(子)テーブルの間の外部キー関係を定義していることを理解します。しかし、以下のBlogクラスでは、public List<Post> Posts { get; set; }
プロパティの使用は何ですか?私は、このプロパティを削除して、このモデルのうち、SQL Serverデータベースを生成する場合、私はまだ、データベースが正常にBlog
テーブルEntity Frameworkコードでの外部キーの定義
namespace EFGetStarted.AspNetCore.NewDb.Models
{
public class BloggingContext : DbContext
{
public BloggingContext(DbContextOptions<BloggingContext> options)
: base(options)
{ }
public DbSet<Blog> Blogs { get; set; }
public DbSet<Post> Posts { get; set; }
}
public class Blog
{
public int BlogId { get; set; }
public string Url { get; set; }
public List<Post> Posts { get; set; }
}
public class Post
{
public int PostId { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public int BlogId { get; set; }
public Blog Blog { get; set; }
}
}
[リスト投稿]は、[ナビゲーションプロパティ](https://msdn.microsoft.com/en-us/library/jj713564(v=11113).aspxf)で、投稿からのアクセスに便利ですブログ。 –
Jasen
@Jasenあなたのリンクが壊れている、それはhttps://msdn.microsoft.com/en-us/library/jj713564(v=vs.113).aspx – Tim
であるはずです。 URL。 – Jasen