why is EntityBase2.IsNew writable

Posts   
 
    
mkamoski avatar
mkamoski
User
Posts: 116
Joined: 06-Dec-2005
# Posted on: 24-Apr-2006 16:50:20   

All--

I am scratching my head about this one.

Why is EntityBase2.IsNew writable?

Why isn't this property ReadOnly?

In what cases would one want a class consumer to set this property?

It seems to me that IsNew(), in common usage, reflects an object's internally maintained value that indicates the current object state, which is derived from the result and status of action operations carried out on the given object. In this way, it does not make sense that class consumer should be able to set a given object IsNew; rather, whether or not an object IsNew is a direct result of the objects lifecylce operations, such as the constructor call, a call to Save(), and so on.

Can anyone shed any light on this?

What do you think?

Please advise.

Thank you.

--Mark Kamoski

JimHugh
User
Posts: 191
Joined: 16-Nov-2005
# Posted on: 24-Apr-2006 17:20:10   

From Generated code - Using the entity classes, SelfServicing

Reading an entity into memory first can be somewhat inefficient, since all we need to do is an update of an entity row in the database.

Option 2 is more efficient in that it just starts an update, without first reading the data from the database. The following code performs the same update as the previous example code illustrating option 1. Even though the PK field is changed, it is not updated, because it is not previously fetched from the database. // [C#] CustomerEntity customer = new CustomerEntity(); customer.CustomerID="CHOPS"; customer.IsNew=false; customer.Phone = "(605)555-4321"; customer.Save();