我开始使用 BLToolkit 并且有一个新的优势:InsertOrReplace 当我尝试使用它时出现异常:“InsertOrUpdate 方法不支持标识字段'Margin.id'” 我的模型在这里:
[TableName("Margin")]
public class Margin
{
[PrimaryKey, Identity] public int id;
[NotNull] public string StoreID;
[PrimaryKey] public int? PrTypeID;
public decimal MarginRate;
[Association(ThisKey = "PrTypeID", OtherKey = "ProductID", CanBeNull = true)] public Product Product;
}
调用方法:
db.InsertOrReplace(new CSSWarranty.DataModel.DataModel.Margin()
{
MarginRate = newMargin.Margin,
PrTypeID = newMargin.ProductTypeID == 0 ? null : newMargin.ProductTypeID,
StoreID = newMargin.StoreID,
id = newMargin.MarginID
});
可能有人可以说如何使用下一个构造: db.Margin.InsertOrUpdate(x,y) 大家好!
我不明白为什么这个例子有效:
[TableName("Notification")]
public class Notification
{
[PrimaryKey] public string NotificationID;
public string Note;
}
称呼:
var db = new RetailerDb()
db.InsertOrReplace(new DataModel.DataModel.Notification()
{
Note = note,
NotificationID = "ConfirmNote"
});
数据库类:
private var db = new RetailerDb();
public class RetailerDb : DbManager
{
public RetailerDb() : base("DBConnection")
{
}
public Table<DataModel.Margin> Margin
{
get { return GetTable<DataModel.Margin>(); }
}
}