忽略基础类/完全在实体框架5 code接口第一 [英] Ignore base class / interfaces completely in entity framework 5 code first

查看:97
本文介绍了忽略基础类/完全在实体框架5 code接口第一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下实体类:

[System.ComponentModel.DataAnnotations.Schema.Table("User")]
public class User: UserBase, IPersistCustom<Entity> { ... }

根据您所使用的层次结构映射的类型,EF会生成任何一个描述符列或拆分表。有没有办法让EF完全忽略了这个类继承的东西或实现一个接口的事实?

Depending on the type of hierarchy mapping you use, EF will generate either a descriptor column or split tables. Is there a way to have EF completely ignore the fact that this class inherits from something or implements an interface?

我的意思并不是只忽略基类的属性。

I don't mean just ignoring base class properties.

推荐答案

如果你标记你的基类(ES)是抽象的,使用表每个具体类型的方法,这可能工作。喜欢的东西;

If you mark your base class(es) as abstract and use table per concrete type approach this may work. Something like;

context.Entity<User>().Map(p =>
        {
            p.MapInheritedProperties();
            p.ToTable("Users");
        });           

引用<一个href="http://weblogs.asp.net/manavi/archive/2011/01/03/inheritance-mapping-strategies-with-entity-framework-$c$c-first-ctp5-part-3-table-per-concrete-type-tpc-and-choosing-strategy-guidelines.aspx"相对=nofollow>这个。

这篇关于忽略基础类/完全在实体框架5 code接口第一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆