标签:
//添加引用 public string UsingDirectives(bool inHeader, bool includeCollections = true) { return inHeader == string.IsNullOrEmpty(_code.VsNamespaceSuggestion()) ? string.Format( CultureInfo.InvariantCulture, "{0}using System;{1}{3}" + "{2}", inHeader ? Environment.NewLine : "", includeCollections ? (Environment.NewLine + "using System.Collections.Generic;") : "", inHeader ? "" : Environment.NewLine, Environment.NewLine + "using System.Runtime.Serialization;") : ""; } //给属性增加[DataMember] public string Property(EdmProperty edmProperty) { return string.Format( CultureInfo.InvariantCulture, "{5}{0} {1} {2} {{ {3}get; {4}set; }}", Accessibility.ForProperty(edmProperty), _typeMapper.GetTypeName(edmProperty.TypeUsage), _code.Escape(edmProperty), _code.SpaceAfter(Accessibility.ForGetter(edmProperty)), _code.SpaceAfter(Accessibility.ForSetter(edmProperty)), "[DataMember]" + Environment.NewLine); } //上面没有对齐,加一个tab public string Property(EdmProperty edmProperty) { return string.Format( CultureInfo.InvariantCulture, "{5}\t{0} {1} {2} {{ {3}get; {4}set; }}", Accessibility.ForProperty(edmProperty), _typeMapper.GetTypeName(edmProperty.TypeUsage), _code.Escape(edmProperty), _code.SpaceAfter(Accessibility.ForGetter(edmProperty)), _code.SpaceAfter(Accessibility.ForSetter(edmProperty)), "[DataMember]" + Environment.NewLine); } //给类添加[DataContract] public string EntityClassOpening(EntityType entity) { return string.Format( CultureInfo.InvariantCulture, "{4}{0} {1}partial class {2}{3}", Accessibility.ForType(entity), _code.SpaceAfter(_code.AbstractOption(entity)), _code.Escape(entity), _code.StringBefore(" : ", _typeMapper.GetTypeName(entity.BaseType)), "[DataContract]" + Environment.NewLine); } 生成的实体类为 //------------------------------------------------------------------------------ // <auto-generated> // This code was generated from a template. // // Manual changes to this file may cause unexpected behavior in your application. // Manual changes to this file will be overwritten if the code is regenerated. // </auto-generated> //------------------------------------------------------------------------------ namespace model { using System; using System.Collections.Generic; using System.Runtime.Serialization; [DataContract] public partial class news { [DataMember] public int id { get; set; } [DataMember] public string title { get; set; } [DataMember] public string body { get; set; } [DataMember] public string author { get; set; } [DataMember] public Nullable<System.DateTime> created { get; set; } [DataMember] public Nullable<System.DateTime> modified { get; set; } } }
entity framework model.tt 模板修改示例
标签:
原文地址:http://www.cnblogs.com/joeycih/p/4841046.html