I start using BLToolkit and there is a new advantage: InsertOrReplace When I try to use it there is an exception: "InsertOrUpdate method does not support identity field 'Margin.id'" My Model here:
[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;
}
Call the method:
db.InsertOrReplace(new CSSWarranty.DataModel.DataModel.Margin()
{
MarginRate = newMargin.Margin,
PrTypeID = newMargin.ProductTypeID == 0 ? null : newMargin.ProductTypeID,
StoreID = newMargin.StoreID,
id = newMargin.MarginID
});
May be someone can say how to use the next construction: db.Margin.InsertOrUpdate(x,y) All regards!
I don't understand why this example is working:
[TableName("Notification")]
public class Notification
{
[PrimaryKey] public string NotificationID;
public string Note;
}
Call:
var db = new RetailerDb()
db.InsertOrReplace(new DataModel.DataModel.Notification()
{
Note = note,
NotificationID = "ConfirmNote"
});
DB class:
private var db = new RetailerDb();
public class RetailerDb : DbManager
{
public RetailerDb() : base("DBConnection")
{
}
public Table<DataModel.Margin> Margin
{
get { return GetTable<DataModel.Margin>(); }
}
}