Detail instructions are on ScottGu’s blog. Honestly, Linq to SQL’s GUI is much easier to use for NTier dummies, I was surprised by its Stored Procedure support, just by drag and drop, then through ‘configure behavvior…’->’customize’, all the parameters of stored procedure are shown in the list! The amazing part is, for update sp, the original values are included.
Cool! Easy, and the data reading is very fast. (I know I haven’t optimize my NHibernate code very well. ) Now my only concern is, if Linq to SQL always generates DAL and Entities together, then is it possible to unit test entity object only?
One bug in Linq to SQL I found so far, right click menu, view code, I got an error message says:
The name “MyProjectName.MyModuleName” is not a valid identifier. Please choose a different name.
I had to change project name to MyProjectName_MyModuleName to avoid this error. How come Microsoft doesn’t link dot appear in project name?
Another trick is, our stored procedure need developer passing user login for audit purpose. In Linq to Sql Gui view, only class property can be inserted as sp’s parameter. So I added an extra property called UserLogin into my model/table, then delete the auto gen code in XXX.designer.cs, add following lines to partial class:
public partial class MyClass
public string UserLogin
return Environment.UserDomainName + “\\” + Environment.UserName;
//or return System.Security.Principal.WindowsIdentity.GetCurrent().Name;
But the piece of code might be override by dbml regenerate. Instead, I moved those code into a BaseTable class, then change the entity class inherited from this BaseTable. Afterwards, I can change the UpdateEntity method in desinger.cs file, replace the original default(string) to obj.UserLogin. This method won’t be overrode by auto-gen that often. I wish Linq designer can take non-column properties in the future.