我正在使用servicestack,ormlite和mysql以及在事务中创建的链接表。使用连接Save方法,它应该(根据文档)使用标识值更新模型。但事实并非如此。
public bool SaveWithCredentials<T>(T model)
{
SetDefaultValues(false, model);
var ret = Db.Save(model);
return ret;
}
(以模特编辑) 模特:
[Alias("orderEvent")]
public class OrderEvent
{
[AutoIncrement]
[Alias("Identity")]
public long Identity { get; set; }
[Required]
[StringLength(DbConstraints.STRING_36, DbConstraints.STRING_36)]
[Alias("Id")]
public string Id { get; set; }
[Required]
[StringLength(DbConstraints.STRING_36, DbConstraints.STRING_36)]
[Alias("orderId")]
public string OrderId { get; set; }
[Required]
[Alias("meaning")]
public int Meaning { get; set; }
[Required]
[Alias("subMeaning")]
public int SubMeaning { get; set; }
[Alias("quantity")]
public int Quantity { get; set; }
[Required]
[Alias("type")]
public int Type { get; set; }
[StringLength(DbConstraints.STRING_36, DbConstraints.STRING_36)]
[Alias("servicesaleId")]
public string ServiceSaleId { get; set; }
[Required]
[StringLength(DbConstraints.STRING_36, DbConstraints.STRING_36)]
[Alias("servicecenterId")]
public string ServiceCenterId { get; set; }
[StringLength(DbConstraints.STRING_36, DbConstraints.STRING_36)]
[Alias("projectId")]
public string ProjectId { get; set; }
[Alias("ecoDate")]
public DateTime EcoDate { get; set; }
[Alias("createdDate")]
public DateTime CreatedDate { get; set; }
[StringLength(DbConstraints.STRING_50)]
[Alias("createdByName")]
public string CreatedByName { get; set; }
[StringLength(DbConstraints.STRING_36, DbConstraints.STRING_36)]
[Alias("createdbyuserId")]
public string CreatedByUserId { get; set; }
[StringLength(DbConstraints.STRING_2000)]
[Alias("generalDescription")]
public string GeneralDescription { get; set; }
[Required]
[StringLength(DbConstraints.STRING_50)]
[Alias("sysecoactionId")]
public string SysEcoActionId { get; set; }
[StringLength(50)]
[Alias("sysOrderSerie")]
public string SysOrderSerie { get; set; }
[Alias("orderNbr")]
public int? OrderNbr { get; set; }
[Alias("itemNbr")]
public int? ItemNbr { get; set; }
}
IDBConnection.Save应该使用模型中的自动增量标识更新字段,以便我可以在链接表中设置外键,但它不会。
有没有人有任何想法?我不能做插入方法,因为它会让我做重大改写 - 这种方式否定了Save方法的目的!
更新 用insert方法在测试方法中尝试了模型,然后我得到了返回的标识。
public long InsertForIdWithCredentials<T>(T model)
{
SetDefaultValues(false, model);
var ret = Db.Insert(model, selectIdentity: true);
return ret;
}
上述代码在返回身份时没有问题,即使它是通用的。
/埃里克