WCF and IsNew Property

Posts   
 
    
xc_lw2000
User
Posts: 48
Joined: 12-Dec-2006
# Posted on: 23-Mar-2012 11:24:56   

I'm using v3.1,Adapter,WCF

I have a view MyView mapped to entity MyViewEntity,and a table MyTable mapped to MyTableEntity. MyView contains all MyTable's fields, like this


create view MyView 
as
select MyTable.*,OtherField
from MyTable

In clinet side, I binding contro to MyViewEntity, if user modify any field of MyViewEntity,then I update the reality table. So I must convert MyViewEntity to MyTableEntity. see bellow


//Fetch MyViewEntiy
MyViewEntity view = Service.GetMyView();
//user modify view's field value
// some other code
//
//










//after user make some change,I want to update table's record
MyTableEntity table = new MyTableEntity();
//copy PK fields
table.SetNewFieldValue("PK",view.PK)
table.Fields["PK"].IsChanged=false;

// set other fields
table.SetNewFieldValue("PK",view.PK)
table.Fields["Field"].IsChanged=view.Fields["Field"].IsChanged;
..............................

//set IsNew to false to generate update sql,other than insert sql
table.IsNew = false;

Service.Save(table);

but in the service side,I watch the table.IsNew = true, so the generate sql is Insert into ......................

strange. why the IsNew lost after pass from client to server side? How to resolve this problem? I do not want modify my Service.Save() code,because it's called by other user, I just want to do all works in client side.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 23-Mar-2012 21:00:42   

table.IsNew = false is not a guarantee that the entity will be updated. Here is some reasons behind that fact: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=17186&StartAtMessage=0&#96570

add this to your code:

table.Fields.State = EntityState.Fetched;
David Elizondo | LLBLGen Support Team