Can Entity Developer create interfaces?
Can Entity Developer create interfaces?
Like the title says. I usually create an interface for my entities. Does ED do that as well?
Re: Can Entity Developer create interfaces?
1. Add a new custom template in your model with the following code:
2. Set the File Per Class property of the EnitytObject template to True and modify the template. Replace:
with
If you want the files with interfaces be generated in separate folders, implement the changes in the custom template which are described at http://forums.devart.com/viewtopic.php?f=32&t=26144.
Code: Select all
<#@ template language="C#" #>
<#@ assembly name="System.Xml" #>
<#@ assembly name="System.Data.Entity" #>
<#@ assembly name="System.Data.Entity.Design" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Collections" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Xml" #>
<#@ import namespace="System.Linq" #>
<#@ property name="HeaderTimestampVersionControlTag" category="Generation" type="System.String" description="If this option is set, the standard date/time-stamp in the file header will be replaced with the specified tag (e.g. a version control tag for Subversion, Git, etc.)" #>
<#@ property name="InterfacesOutput" category="Output" type="OutputInfo" editor="OutputInfoEditor" description="Specifies output for the generated entity classes." #>
<#
// Begin generation
string namespaceName = codeProvider.GetValidIdentifier(model.Namespace);
//------------------------------------------------------------------------------
// Interface generation for entities
//------------------------------------------------------------------------------
foreach (EntityClass cls in model.Classes) {
output.Extension = ".cs";
output.PushOutputRedirection(InterfacesOutput, "", model.FileName + ".I" + cls.Name, OverwriteMode.Overwrite);
GenerateFileHeader();
#>
namespace <#= namespaceName #>
{
<#= codeProvider.FormatClassAccess(cls.Access) #> interface <#= codeProvider.GetValidIdentifier("I" + cls.Name) #>
{
<#
foreach (EntityProperty property in cls.Properties) {
string currentPropertyType = codeProvider.GetNullableType(property.Nullable, property.Type);
string inheritanceModifier = property.InheritanceModifier == MemberInheritanceModifier.None ? "" : " " + codeProvider.FormatMemberInheritanceModifier(property.InheritanceModifier);
#>
<#= inheritanceModifier #> <#= currentPropertyType #> <#= codeProvider.GetValidIdentifier(property.Name) #>
{
get;
set;
}
<#
}
foreach (EntityRelationProperty relationProperty in cls.RelationProperties)
if (relationProperty.Generate) {
string inheritanceModifier = relationProperty.InheritanceModifier == MemberInheritanceModifier.None ? "" : " " + codeProvider.FormatMemberInheritanceModifier(relationProperty.InheritanceModifier);
if (relationProperty.Multiplicity == Multiplicity.Many) { // if Multiplicity.Many
#>
<#= inheritanceModifier #> EntityCollection<<#= codeProvider.GetValidIdentifier(relationProperty.RelationClass.Name) #>> <#= codeProvider.GetValidIdentifier(relationProperty.Name) #>
<#
}
else{
#>
<#= inheritanceModifier #> <#= codeProvider.GetValidIdentifier(relationProperty.RelationClass.Name) #> <#= codeProvider.GetValidIdentifier(relationProperty.Name) #>
<#
}
#>
{
get;
set;
}
<#
}
#>
}
}
<#
output.PopOutputRedirection();
}
// End of generation
#>
<#+
//////////////////////////////////////////////////////////////////////////////////
//
// Method GenerateFileHeader()
// Header comments for each generated file.
//
//////////////////////////////////////////////////////////////////////////////////
private void GenerateFileHeader() {
#>
//------------------------------------------------------------------------------
// This is auto-generated code.
//------------------------------------------------------------------------------
// This code was generated by Devart Entity Developer tool using Entity Framework EntityObject template.
// <#= String.IsNullOrEmpty(HeaderTimestampVersionControlTag) ? "Code is generated on: " + DateTime.Now : HeaderTimestampVersionControlTag #>
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//------------------------------------------------------------------------------
using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Runtime.Serialization;
using System.Xml.Serialization;
<#+
if (model.Settings.EntityFrameworkVersion < EntityFrameworkVersion.Version6) {
#>
using System.Data.EntityClient;
using System.Data.Metadata.Edm;
using System.Data.Objects;
using System.Data.Objects.DataClasses;
<#+
}
else {
#>
using System.Data.Entity.Core.EntityClient;
using System.Data.Entity.Core.Metadata.Edm;
using System.Data.Entity.Core.Objects;
using System.Data.Entity.Core.Objects.DataClasses;
<#+
}
}
#>
Code: Select all
<#= classAccess #> <#= classInheritanceModifier #>partial class <#= currentClassName #> : <#= baseList #><# if (ImplementCloneable) { #>, ICloneable<# } #>
Code: Select all
<#= classAccess #> <#= classInheritanceModifier #>partial class <#= currentClassName #> : <#= baseList #>, <#= codeProvider.GetValidIdentifier("I" + cls.Name) #> <# if (ImplementCloneable) { #>, ICloneable<# } #>
Re: Can Entity Developer create interfaces?
Wow, that's great! I just finally got around to purchasing ED so I'm committed to learning it now
I looked up adding a template in the help section and followed that to the point where you are at the "Add Template" window. Is that how I create a custom template? And if so which one of the types of templates do I select?
Thanx!
I looked up adding a template in the help section and followed that to the point where you are at the "Add Template" window. Is that how I create a custom template? And if so which one of the types of templates do I select?
Thanx!
Re: Can Entity Developer create interfaces?
This is the way how to add a new custom template in your model: navigate to Tools > Entity Developer > Model Explorer, right click on the Templates node > New Blank Template.
Another way: add any predefined template (right click on Templates > Add Template), then right click on a newly added template > Copy to Model Folder. After this, open it (by double click) and modify with embedded T4 Editor.
Another way: add any predefined template (right click on Templates > Add Template), then right click on a newly added template > Copy to Model Folder. After this, open it (by double click) and modify with embedded T4 Editor.
-
- Posts: 1
- Joined: Fri 25 Apr 2014 14:27
Re: Can Entity Developer create interfaces?
Alternatively, you can download my project on Codeplex. I have a working example that you can copy.
https://entityinterfacegenerator.codeplex.com/
It generates the interface files that you need for IoC purposes.
https://entityinterfacegenerator.codeplex.com/
It generates the interface files that you need for IoC purposes.
Re: Can Entity Developer create interfaces?
3 years later. Is there any improvements on the way to implement Interface ?
Vincent
Vincent
-
- Devart Team
- Posts: 2420
- Joined: Wed 02 Nov 2011 09:44
Re: Can Entity Developer create interfaces?
We provided the code of a new custom template above. You can use it and create your custom template.
Please describe what improvements you would like to see.
Please describe what improvements you would like to see.