【问题标题】:Adding ServiceStack OrmLite attributes in code instead of a property在代码中添加 ServiceStack OrmLite 属性而不是属性
【发布时间】:2015-05-23 10:57:26
【问题描述】:

ServiceStack.OrmLite 是否支持像 EntityFramework 中一样使用 Linq 的属性?

不要使用 [PrimaryKey] 或 [CustomField] 来装饰每个属性,而是有一个使用 LinQ 为每个属性设置属性的初始化程序类。

类似

Entity<User>().SetCustomField(p => p.Id, Entity.PrimaryKey);

可能吗?

【问题讨论】:

    标签: c# linq servicestack ormlite-servicestack


    【解决方案1】:

    在 OrmLite 中Id 自动为主键,否则假设第一个属性为主键。但是你也可以使用ServiceStack的动态属性API在StartUp上动态添加属性,例如:

    typeof(User)
        .GetProperty("Id")
        .AddAttributes(new PrimaryKeyAttribute());
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-07
      • 1970-01-01
      • 1970-01-01
      • 2010-11-06
      • 1970-01-01
      • 2013-12-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多