简体   繁体   English

移动DbSet <TEntity> 实体框架核心中的单独类的属性

[英]Move DbSet<TEntity> properties to a Separate Class in Entity Framework Core

Here is what I have currently in MyContext class 这是我目前在MyContext类中的内容

 public class MyContext:DbContext
 {           
        public  DbSet<Country> Countries { get; set; }
        public  DbSet<State> States { get; set; }
 }

What I want is to place all these DbSet properties into a separate file and just have one statement on MyContext class to add all DbSet from that separate file. 我想要的是将所有这些DbSet属性放在一个单独的文件中,并在MyContext类上只有一个语句来添加该单独文件中的所有DbSet

Use a partial class and define the DbSet<T> properties there. 使用partial类并在DbSet<T>定义DbSet<T>属性。

MyContext.cs MyContext.cs

public partial class MyContext:DbContext
{           
}

MyContextProperties.cs MyContextProperties.cs

public partial class MyContext:DbContext
{           
    public  DbSet<Country> Countries { get; set; }
    public  DbSet<State> States { get; set; }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM