ServiceStack OrmLite - 数据库优先和多个主键
ServiceStack OrmLite - database first & multiple primary keys
我必须处理现有的 Db 并且想使用 ServiceStack 的 OrmLite。
因此我使用 OrmLite T4 模板创建了 Poco 类。
问题:我想保存到具有多个主键的 table。
public partial class DbUserGroup
{
[Required]
public int Userid { get; set;} // this is a primary key
[Required]
public int Groupid { get; set;} // this is a primary key
public int Ranking { get; set;}
public bool Isprimary { get; set;}
}
目前无法使用 Db.Save(userGroup)。有什么方法可以使用 ServiceStack 的 OrmLite 解决这个问题。
我通过将 [PrimaryKey] 添加到两个属性来解决它。
public partial class DbUserGroup
{
[Required]
[PrimaryKey]
public int Userid { get; set;} // this is a primary key
[Required]
[PrimaryKey]
public int Groupid { get; set;} // this is a primary key
public int Ranking { get; set;}
public bool Isprimary { get; set;}
}
多个主键不存在。 A multi-column 主键是的。
请看看这个linkhttps://github.com/ServiceStack/ServiceStack.OrmLite#limitations
如其所说
A potential workaround to support tables with multiple primary keys is to create an auto generated Id property that returns a unique value based on all the primary key fields
我必须处理现有的 Db 并且想使用 ServiceStack 的 OrmLite。
因此我使用 OrmLite T4 模板创建了 Poco 类。
问题:我想保存到具有多个主键的 table。
public partial class DbUserGroup
{
[Required]
public int Userid { get; set;} // this is a primary key
[Required]
public int Groupid { get; set;} // this is a primary key
public int Ranking { get; set;}
public bool Isprimary { get; set;}
}
目前无法使用 Db.Save(userGroup)。有什么方法可以使用 ServiceStack 的 OrmLite 解决这个问题。
我通过将 [PrimaryKey] 添加到两个属性来解决它。
public partial class DbUserGroup
{
[Required]
[PrimaryKey]
public int Userid { get; set;} // this is a primary key
[Required]
[PrimaryKey]
public int Groupid { get; set;} // this is a primary key
public int Ranking { get; set;}
public bool Isprimary { get; set;}
}
多个主键不存在。 A multi-column 主键是的。 请看看这个linkhttps://github.com/ServiceStack/ServiceStack.OrmLite#limitations
如其所说
A potential workaround to support tables with multiple primary keys is to create an auto generated Id property that returns a unique value based on all the primary key fields