Can Entity Developer create interfaces?
Posted: Thu 07 Mar 2013 15:27
Like the title says. I usually create an interface for my entities. Does ED do that as well?
Discussion forums for open issues and questions concerning database tools, data access components and developer tools from Devart
https://forums.devart.com/
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<# } #>