StoreGeneratedPattern

Nov 16, 2010 at 3:00 PM

I have a property on an Entity called LastUpdateDate that I have set the StoreGeneratedPattern to "Computed".  I have also set the CSLA Setter to None.  The LastUpdateDate is actually generated at the database.  The problem is that your templates still want to write to this property even though there is no Csla setter and EF doesn't like you writing to a property that is set to Computed or Identity.  Would it be possible to remove any writing of a property with evither no Csla Setter or is set to Computed.  If not, I always have the work-around of setting both setter and getter to None and implement the properties myself, but I was wondering if there was an easier way.

Coordinator
Nov 16, 2010 at 3:19 PM

Hi brencld.

EF does not handle default database values very well. If you don't supply the value before inserting an entity to the database, you will get SqlDateTime overflow (http://stackoverflow.com/questions/584556/how-to-use-default-column-value-from-database-in-entity-framework). If you set column property to "Computed" in your EF model, next time you refresh the model that value will be lost. 

My solution: I have created a stored procedure that returns getdate() from the database server. I use that value in partial BeforeInsert method of my Business object.

Is this solution ok for you? If not, I'll add this request to the Issue Tracker.

Regards,

Josip

Nov 16, 2010 at 3:32 PM

Howdy jbudimir,

Thanks for the reply, but it is incorrect.  It will return the database value, but you have to set it to computed in the designer and also manually set the property to Computed in the designer file due to a known bug in the design editor. 

You can find more info on that bug here http://msdn.microsoft.com/en-us/library/bb738536.aspx

 I use triggers to generate the creation date and last update date, and as I have implemented the work around I described in my above post, it works perfectly.

Coordinator
Nov 16, 2010 at 5:07 PM

Maybe I did not express myself correctly. If you set property in the designer manually, this will work. But every time you refresh model from the database, this property will be reseted. So you'll have to remember that every time you refresh the model from the database, you need to set this property again.

I'll add this request to the Issue Tracker.

 

 

Coordinator
Nov 16, 2010 at 5:08 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
Nov 16, 2010 at 5:26 PM

I have changed the template and now if property does not have setter, property value is not written to the EF entity during save operation. You can download the latest template from the source repository and simply copy->paste to your project. Don't forget to change emdx path after doing that. If you want I can build new VSIX file for you.

Regards,

Josip

 

Nov 16, 2010 at 5:42 PM

Good point on the database updating.  This is a nasty nasty bug.

Dec 8, 2010 at 7:16 PM

Hurrah!  VS2010 SP1 beta looks like it fixes the entity designer.