一、准备工作
    使用NUGET安装Entity Framework 6,下载MySql Connector/Net 6.9.5
 
二、创建实体
    我们在下面创建了两个类(博客和文章),并使用了虚拟属性标识了他们的关系。这使得实体框架具有了延迟加载特性,延迟加载意味着从数据库加载内容的时候将会自动加载关联实体的内容(除了我们设置了禁用延迟加载)
  
public class Blog
    {
        public int BlogId { get; set; }
        
        public string Name { get; set; }

        public virtual 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 virtual Blog Blog { get; set; }
    }
View Code

 

相关文章:

  • 2022-01-19
猜你喜欢
  • 2021-07-02
  • 2022-01-07
  • 2021-12-07
相关资源
相似解决方案