subsonic / SubSonic-3.0-Templates

T4 Template Project for the peeps
http://subsonic.github.io/
105 stars 46 forks source link

Adding FetchById back into the ActiveRecord template #22

Open jamesewelch opened 15 years ago

jamesewelch commented 15 years ago

To support backwards compatibility and make it a bit easier for us using SubSonic 2.x projects to move into 3.0. Can FetchById be added back to the template?

Here's some sample code that brings back the same functionality by just passing off the value to the SingleOrDefault method. This code should be added to ActiveRecord.tt file near the SingleOrDefault methods.

public static <#=tbl.ClassName#> FetchById(<#= tbl.PK.SysType#> keyValue)
{
     return SingleOrDefault(x=>x.<#= tbl.PK.CleanName #> == keyValue);
}