The author simply makes fun of the repository, not the entity. EntityFramework generates ObjectQueries, but it wraps them, and its repository returns IObjectQueries. He does this so that he can easily mock the data, and then during the save he simply checked the entities.
If you are just trying to create a "mock" repository, you can create your own T4 template and iterate over the edmx file and generate the code. But there is no reason to create POCOS? They already exist, why do you need to recreate them? He abstracted everything into a βcommonβ FakeObjectSet, so there really isnβt much code written?
You are trying to generate this:
public IObjectSet<Blog> Blogs { get { return _blogs ?? (_blogs = new FakeObjectSet<Blog>()); } set { _blogs = value as FakeObjectSet<Blog>; } } private FakeObjectSet<Blog> _blogs;
If so, I'm going to guess that you will spend more time on T4, then you just write it.
T4 example without class declaration ... you can make full t4 by running this blog
<# foreach (EntitySet set in container.BaseEntitySets.OfType<EntitySet>()) { #> public IObjectSet<<#=MultiSchemaEscape(set.ElementType, code)#>> { get{ return <#=code.FieldName(set)#> ?? ( <#=code.FieldName(set)#> = FakeObjectSet<<#=MultiSchemaEscape(set.ElementType, code)#>>("<#=set.Name#>")); } set{ <#=code.FieldName(set)#> = value as FakeObjectSet<<#=MultiSchemaEscape(set.ElementType, code)#>>("<#=set.Name#>"); } } private FakeObjectSet<<#=MultiSchemaEscape(set.ElementType, code)#>> <#=code.FieldName(set)#>; <# } #>
To generate this code:
public IObjectSet<Blogs>{ get{ return _Blogs?? ( _Blogs = FakeObjectSet<Blog>("Blogs")); } set{ _Blogs= value as FakeObjectSet<Class>("Blogs"); } } private FakeObjectSet<Blog> _Blogs;
Side note.
IObjectSet is contained in System.Data, so add a link to System.Data.Entity.dll
Nix
source share