简体   繁体   English

ServiceStack.OrmLite继承映射

[英]ServiceStack.OrmLite inheritance mapping

Does ServiceStack.OrmLite support inheritance mapping? ServiceStack.OrmLite是否支持继承映射?

Like DevExpress XPO: Inheritance Mapping or nHibernate Inheritance . 像DevExpress XPO: 继承映射或nHibernate 继承

For example (c#): 例如(c#):

public abstract class EventBase
{
   public string Name { get;set; }
}
public class NormalEvent: EventBase
{
   public string A { get;set; }
}
public class SuperDuppaEvent:EventBase
{
   public string B { get;set; }
}

In database exist one table 'EventBase' with all Columns/Properties from 'NormalEvent', 'SuperDuppaEvent' and from 'EventBase' too. 在数据库中,存在一个表“ EventBase”,其中所有列/属性均来自“ NormalEvent”,“ SuperDuppaEvent”和“ EventBase”。

In the documentation exist the 'AliasAttribute' but it doesn't work. 文档中存在“ AliasAttribute”,但它不起作用。

No OrmLite does not support inheritance mapping. 没有OrmLite不支持继承映射。 It's a core expectation in OrmLite that each POCO maps 1:1 with the RDBMS table it represents. OrmLite的核心期望是每个POCO与其所代表的RDBMS表以1:1映射。 So by default each of your classes will map to an RDBMS table with the same name: 因此,默认情况下,您的每个类都将映射到具有相同名称的RDBMS表:

  • NormalEvent > NormalEvent table NormalEvent > NormalEvent表
  • SuperDuppaEvent > SuperDuppaEvent table SuperDuppaEvent > SuperDuppaEvent表

If you want different behavior you'd need to map the POCO classes 1:1 with how you want it laid out in the database, eg: 如果您想要不同的行为,则需要将POCO类1:1映射到数据库中的布局方式,例如:

class NormalEvent
{
    public string A { get; set; }
    public int EventBaseId { get; set; }
}

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

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