C# – Linq To SQL Attach/Refresh Entity Object

clinqlinq-to-sqlnet

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

Best Answer

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?