• EntityFramework+WCF


    首先需要在服务对象实例上面添加数据契约[DataContract]和  [DataMember],当然直接在类中修改也可以,但是对于tt模板来说一旦保存以后数据就会重新生成,

    所以得在tt模板中修改

    禁用代理类

    添加对象属性

    //添加引用
    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;")
            : "";
    }
    //上面没有对齐,加一个tab
    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);
    }
    
    //给类添加[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);
    }
  • 相关阅读:
    java实现文件变化监控
    java实现串口通讯
    Linux From Scratch(从零开始构建Linux系统,简称LFS)(三)
    Linux From Scratch(从零开始构建Linux系统,简称LFS)(二)
    Linux From Scratch(从零开始构建Linux系统,简称LFS)(一)
    OAuth 2.0
    DDD学习专题
    Java未来也许不再是电商的首选开发语言
    Axon
    CQRS模式介绍
  • 原文地址:https://www.cnblogs.com/happygx/p/3474236.html
Copyright © 2020-2023  润新知