我想在 EF 4.5 edmx .tt 文件中放置两个 using 指令,但遇到了麻烦。4.0 的语法不同并且更容易操作。
任何帮助将不胜感激.... EF 4.0 语法:
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.ServiceModel;
4.5 语法
public string UsingDirectives(bool inHeader, bool includeCollections = true)
{
return inHeader == string.IsNullOrEmpty(_code.VsNamespaceSuggestion())
? string.Format(
CultureInfo.InvariantCulture,
"{0}using System;{1}" +
"{2}",
inHeader ? Environment.NewLine : "",
includeCollections ? (Environment.NewLine + "using System.Collections.Generic;") : "",
inHeader ? "" : Environment.NewLine)
: "";
}
我需要在 .tt 文件中添加以下属性:
EF 4.0 语法
[Serializable]
[DataContract(IsReference = true)]
<#=Accessibility.ForType(entity)#> <#=code.SpaceAfter(code.AbstractOption(entity))#>partial class <#=code.Escape(entity)#><#=code.StringBefore(" : ", code.Escape(entity.BaseType))#>
{
<#
4.5 语法
public string EntityClassOpening(EntityType entity)
{
return string.Format(
CultureInfo.InvariantCulture,
"{0} {1}partial class {2}{3}",
Accessibility.ForType(entity),
_code.SpaceAfter(_code.AbstractOption(entity)),
_code.Escape(entity),
_code.StringBefore(" : ", _typeMapper.GetTypeName(entity.BaseType)));
}
4.0 语法
void WriteProperty(string accessibility, string type, string name, string getterAccessibility, string setterAccessibility)
{
#> [DataMember]
<#=accessibility#> <#=type#> <#=name#> { <#=getterAccessibility#>get; <#=setterAccessibility#>set; }
<#+
}
4.5 语法我找不到任何类似的语法**
基本上,我希望从 edmx 文件重新生成类时的输出如下所示:
using System;
using System.Collections.Generic;
using System.Runtime.Serialization; using System.ServiceModel;
namespace YeagerTechModel
{
[Serializable]
[DataContract(IsReference = true)]
public partial class Priority
{
public Priority()
{
this.Projects = new HashSet<Project>();
}
[DataMember]
public short PriorityID { get; set; }
[DataMember]
public string Description { get; set; }
[DataMember]
public virtual ICollection<Project> Projects { get; set; }
}
}