Hi All,
I'm indicating a very strange problem. I have property named IDProperty, with default value set to 0. I want to insert a new object to database using LINQ. Then I need to save a new ID retrieved from LINQ object to IDProperty to use it later.
Problem is that IDProperty is still set to 0 even when I used SetProperty(IDProperty, order.ID);
Can someone help me, please?
Thanks in advance
Here is my code:
//Property declaration
private static PropertyInfo<int> IDProperty =RegisterProperty(
typeof(BusinessUnit), new PropertyInfo<int>("ID")); public int ID{
get { return GetProperty(IDProperty); } set { SetProperty(IDProperty, value); }}
//Data portal
[
Transactional(TransactionalTypes.TransactionScope)] protected override void DataPortal_Insert(){
using (var ctx = ContextManager<Arrow.BusinessObjects.Core.Dbml.ArrowDBDataContext>.GetManager("ArrowDB", true)){
Arrow.BusinessObjects.Core.Dbml.
BusinessUnit obj = new Arrow.BusinessObjects.Core.Dbml.BusinessUnit();obj.Name = GetProperty(NameProperty);
ctx.DataContext.BusinessUnits.InsertOnSubmit(obj);
ctx.DataContext.SubmitChanges();
this.SetProperty(IDProperty, obj.ID);}
}
Two things to consider.
First, you should typically use LoadProperty() and ReadProperty() in your data portal methods, not SetProperty() and GetProperty().
Second, when you call Save() on the client, are you using the result of that call?
_cust = _cust.Save()
As I discuss in chapters 1 and 2 of the book, the Save() method returns a new object, and if you don't use that new object then you'll never see the changes made to your data in the DataPortal_XYZ methods.
Copyright (c) Marimer LLC