C# – Is having two Model objects for one table a common practice with LINQ-to-SQL / Entity Framework

cdata-layersentity-frameworklinq-to-sql

When using LINQ-to-SQL or Entity Framework, I can easily generate a class for each table which takes care of the CRUD basics:

Info info = new Info();
info.Title = "testing";
db.Infos.InsertOnSubmit(info);
db.SubmitChanges();

And when I make structural changes to a database table, I can easily regenerate the table's model class (simply deleting it in the designer and dragging the table to the designer again). However, this of course overwrites everything that was in the class.

So in order to add extra functionality to each class which does not get deleted when I regenerate the model, I find myself having an extra model class for each table, hence two data layers in effect.

Is this common practice or is there a way to add functionality to the generated classes which does not get overwritten upon regeneration of the classes?

Best Answer

Create a partial class with the same name (in a different source code file) and put whatever extended functionality you want there.