Reputation: 2528
Thanks to the good offices of people here I came to realise that if one has a constructor in a partial class in ones entity model it will be called whenever records are retrieved or when actual new records are created.
I have been searching for a simple example of how one might differentiate between the two so that property assignments added to the constructor are only ever applied to ne records. If anyone knows of such a sample or could provide one here (preferably in VB.net) I would be most grateful.
Here is a typical example of the sort of thing I'd like to only get called when a new record was being created as opposed to whenever a record was retrieved.
Public Sub New()
OrderNumber = te.UpdateAndReturnSalesOrderNumber.FirstOrDefault
OrderDate = Now
Posted = False
End Sub
Thanks
Upvotes: 0
Views: 40
Reputation: 3074
It's been a while since I've played with the partial classes and thus don't remember the order of things.
But, if you have an ID you could check for the default value (i.e., 0 or empty) after EF hydrates your class.
I think I remember doing something like this.
Upvotes: 1