简体   繁体   English

是否可以在Entity Framework Core中创建映射类?

[英]Is it possible to create a mapping class in Entity Framework Core?

In previous versions of Entity Framework we could use EntityTypeConfiguration<TEntity> to configure the mapping for the entity of type TEntity on the constructor. 在先前版本的Entity Framework中,我们可以使用EntityTypeConfiguration<TEntity>在构造函数上配置类型为TEntity的实体的映射。

The other option is to set the mapping on the OnModelCreating method of the DbContext , but this other option is nice because we can leave each mapping in its own place. 另一种选择是设置在映射OnModelCreating的方法DbContext ,但另一种选择是不错的,因为我们可以保留自己的一席之地每个映射。

Now I'm starting to use Entity Framework Core and I could not find the EntityTypeConfiguration<TEntity> class, so I believe things have changed. 现在,我开始使用Entity Framework Core,但找不到EntityTypeConfiguration<TEntity>类,因此我相信情况已经改变。

Is it possible to create a mapping class in the new version of Entity Framework or for now we have to use the OnModelCreating ? 是否可以在新版本的Entity Framework中创建映射类,或者现在我们必须使用OnModelCreating

Unfortunately, OnModelCreating is the preferred way to do it right now. 不幸的是, OnModelCreating是目前首选的方式。 The team (specifically rowanmiller) mentioned that: 团队(特别是rowanmiller)提到:

I think we will probably do this, or something like it, but it is lower priority than some of the other features EF Core is missing at the moment. 我认为我们可能会执行此操作或类似操作,但是它的优先级低于EF Core当前缺少的其他一些功能。

https://github.com/aspnet/EntityFramework/issues/2805 https://github.com/aspnet/EntityFramework/issues/2805

If you read through the comments on that issue, there are some alternative ways to do it, but not "officially" supported ways other than OnModelCreating right now. 如果您OnModelCreating阅读了有关该问题的评论,则可以使用其他方法来完成此操作,但是目前除了OnModelCreating之外,还没有“官方”支持的方法。

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

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