[英]asp.net class library that talks to ef and customizable
I'm trying to make a class library that contains only the core logic of may app.我正在尝试制作一个仅包含 may app 核心逻辑的类库。 I've seen many tutorials that do this but they include the EF core inside that library.
我见过很多这样做的教程,但它们在该库中包含了 EF 核心。 What I want to do is put only all the logic such, adding a category if it doesn't exist yet by passing a
string
.我想要做的是只放置所有逻辑,如果它还不存在,则通过传递
string
添加一个类别。
Here 's what I want to do这是我想要做的
manager
but I don't want this to be the class directly used as my entity.manager
修改的模型,但我不希望这成为直接用作我的实体的类。 I just want this to be the base class of my entity for customization. Here's what I got so far这是我到目前为止所得到的
// class library
public interface IBook{
// some properties here
ICollection<ICategory> Categories { get; set; }
// some more properties...
}
public interface ICategory{
// some properties here
ICollection<IBook> Books { get; set; }
// some more properties...
}
public class Book : IBook {
// implementations...
}
public class Category : ICategory {
// implementations
}
public class BookManager {
public void CreateBook(Book book) {
// some logic
// I'm not sure if I would pass Book or IBook
}
public void AddCategories(List<Category> categories) {
// some logic
// I'm not sure if I would pass Category or ICategory
}
}
// my main app
public class BookInfo {
// some props...
}
public class BookCategory {
// some props...
}
public class MyDB : DbContext{
public DbSet<BookInfo> BookInformations {get; set;}
public DbSet<BookCategory> BookCategories {get; set;}
}
The problems问题
Book
.Book
。 I don't want to use fluent API just to rename this.Discriminator
.Discriminator
数据库的新列。 What is that? Additional Question Am I doing this right?附加问题我这样做对吗? Is it a bad idea?
这是一个坏主意吗? Please enlighten me.
请赐教。 I'm not beginner but I haven't been in the real development team.
我不是初学者,但我没有加入真正的开发团队。
1 .The table name in my database is Book. 1 .我数据库中的表名是Book。 I don't want to use fluent API just to rename this.
我不想使用 fluent API 来重命名它。
To give a class a different table name you can do this with the fluent API but since you don't want to do that you can use the [Table]
attribute for this:要为类指定不同的表名,您可以使用 fluent API 执行此操作,但由于您不想这样做,您可以为此使用
[Table]
属性:
[Table("BookTableName")]
public class Book : IBook {
// implementations...
}
2. I have new column it both database called Discriminator. 2. 我有一个名为 Discriminator 的数据库的新列。 What is that?
那是什么? I do I remove that?
我删除那个?
A discriminator column is used to identify which type each row represents.
鉴别器列用于识别每行代表的类型。 See the docs
查看文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.