Answered by:
Entity Framework , Persistence Ignorance

Question
-
Hi ,
With Model first Approach using Entity Framework designer , i have created mu Model classes , from there database got created with EDMX.
Question is using POCO T4 templates , we can make our Data Access Layer classes to be Persisntence Ignore.
Can we make the POCO classes to be derived from Interfaces , so that my Business layer and Data Access Layer are derived from same Interfaces?
Thanks,
Prasanna
Monday, June 11, 2012 7:44 AM
Answers
-
You can either modify the T4 templates or you can have your partial classes implement the interfaces.
- Proposed as answer by Allen_MSDN Tuesday, June 12, 2012 5:46 AM
- Marked as answer by Allen_MSDN Monday, June 18, 2012 2:26 AM
Monday, June 11, 2012 6:24 PM -
Hi Lakshmi Prasanna,
Welcome to MSDN Forum.
Please open you Model.tt file, look for this line:
foreach (var entity in ItemCollection.GetItems<EntityType>().OrderBy(e => e.Name))
and then looking for this line:
<#=Accessibility.ForType(entity)#> <#=code.SpaceAfter(code.AbstractOption(entity))#>partial class <#=code.Escape(entity)#><#=code.StringBefore(" : ", code.Escape(entity.BaseType))#>
If you have an interface named 'ITest', add it after the code as below.
<#=Accessibility.ForType(entity)#> <#=code.SpaceAfter(code.AbstractOption(entity))#>partial class <#=code.Escape(entity)#><#=code.StringBefore(" : ", code.Escape(entity.BaseType))#>:ITest
Best RegardsAllen Li [MSFT]
MSDN Community Support | Feedback to us
- Marked as answer by Allen_MSDN Monday, June 18, 2012 2:26 AM
Thursday, June 14, 2012 5:47 AM
All replies
-
You can either modify the T4 templates or you can have your partial classes implement the interfaces.
- Proposed as answer by Allen_MSDN Tuesday, June 12, 2012 5:46 AM
- Marked as answer by Allen_MSDN Monday, June 18, 2012 2:26 AM
Monday, June 11, 2012 6:24 PM -
can you suggest or refer material , where i shows how to make my POCO classes inhertited from Interfaces , by changing T4 templates.
Thanks.
Wednesday, June 13, 2012 10:29 AM -
Hi Lakshmi Prasanna,
Welcome to MSDN Forum.
Please open you Model.tt file, look for this line:
foreach (var entity in ItemCollection.GetItems<EntityType>().OrderBy(e => e.Name))
and then looking for this line:
<#=Accessibility.ForType(entity)#> <#=code.SpaceAfter(code.AbstractOption(entity))#>partial class <#=code.Escape(entity)#><#=code.StringBefore(" : ", code.Escape(entity.BaseType))#>
If you have an interface named 'ITest', add it after the code as below.
<#=Accessibility.ForType(entity)#> <#=code.SpaceAfter(code.AbstractOption(entity))#>partial class <#=code.Escape(entity)#><#=code.StringBefore(" : ", code.Escape(entity.BaseType))#>:ITest
Best RegardsAllen Li [MSFT]
MSDN Community Support | Feedback to us
- Marked as answer by Allen_MSDN Monday, June 18, 2012 2:26 AM
Thursday, June 14, 2012 5:47 AM