zoukankan      html  css  js  c++  java
  • 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);
    }
  • 相关阅读:
    ASP.NET MVC EF 连接数据库(一)-----Database First
    设计模式——策略模式
    设计模式——简单工厂模式
    分享一些技术大牛的博客
    有货双中心双活架构实践
    分布式协调服务Zookeeper应用场景
    分布式服务框架资料汇总
    Java线程池ThreadPoolExecutor解析
    服务注册中心Zookeeper和Eureka比较
    JVM内存结构、垃圾回收及性能调优
  • 原文地址:https://www.cnblogs.com/happygx/p/3474236.html
Copyright © 2011-2022 走看看