Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linq To SQL Attach/Refresh Entity Object

In Linq To Sql, when updating one of my entities, Faculty, I am creating a new instance of the Faculty object, then initializing some of the properties with values supplied by the user.

If I attach this new object to the entity set, and submit changes, the properties that I didn't set take on the default value of whatever datatype they are.

How can I refresh the new object so that the properties that have been set keep their values and the properties that haven't been set get the values from the database?

Thanks

like image 839
Ronnie Overby Avatar asked May 22 '09 14:05

Ronnie Overby


2 Answers

Did you try

context.Refresh(RefreshMode.OverwriteCurrentValues, faculty);

after submit changes where context is your linq2sql datacontext and faculty is the entity you want to refresh?

like image 108
a_hardin Avatar answered Oct 04 '22 14:10

a_hardin


What about retrieving the object from the database, then changing the appropriate values, then submitting the update?

like image 27
CSharpAtl Avatar answered Oct 04 '22 16:10

CSharpAtl