zoukankan      html  css  js  c++  java
  • 表实体上面添加特性获取到连接字符串

    public static string ConnectionString(Type type)
    {
    try
    {
    string tableName = type.Name;
    string configName = null;
    object[] arrAttributes = type.GetCustomAttributes(typeof(Attribute), true);
    if (arrAttributes != null)
    {
    TableNameAttribute table = arrAttributes.FirstOrDefault(x => x.GetType().Name.Equals(typeof(TableNameAttribute).Name)) as TableNameAttribute;
    if (table != null)
    {
    tableName = table.TableName;
    configName = table.ConfigName;
    }
    }

    if (string.IsNullOrWhiteSpace(configName))
    {
    configName = GetConfigName(tableName);
    }

    if (string.IsNullOrWhiteSpace(configName))
    {
    return ConnectionString();
    }

    return ConnectionString(configName);
    }
    catch
    {
    return ConnectionString();
    }
    }

    --------------------------------------------------------表实体

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using TRS.Export.FrameEntity.Attributes;

    namespace TRS.Export.Entity
    {
    /// <summary>
    /// TWX_TransportOrder
    /// </summary>
    [Serializable]
    [TableName("TWX_TransportOrder")]
    public partial class TWX_TransportOrder
    {
    private long? _transportorderid;//转运单主键
    private string _transportordercode;//转运单号 出库号
    private long? _tradeorderid;//淘宝交易号
    private string _taobaologisticsid;//物流订单的订单号
    private int? _warehouseid;//虚拟仓库地址
    private DateTime? _warehouseouttime;//出库时间
    private int? _warehouseoutuser;//出库人
    private string _interdeliverycode;//国际物流单号

    }

    -----------------------------------------------------------TableNameAttribute

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace TRS.Export.FrameEntity.Attributes
    {
    public class TableNameAttribute : Attribute
    {
    public string TableName { get; set; }

    public string ConfigName { get; set; }

    public TableNameAttribute(string tableName, string configName = null)
    {
    TableName = tableName;
    ConfigName = configName;
    }
    }
    }

  • 相关阅读:
    collection系列用法-defaultdict()
    collection系列用法-namedtuple()
    collection系列用法-deque双向队列
    Python 拷贝对象(深拷贝deepcopy与浅拷贝copy)
    python 【第四篇】:面向对象(一)
    python之lambda表达式
    python 【第三篇】:函数及参数
    LeetCode 648. Replace Words (单词替换)
    LeetCode 953. Verifying an Alien Dictionary (验证外星语词典)
    LeetCode 970. Powerful Integers (强整数)
  • 原文地址:https://www.cnblogs.com/chengjun/p/8398872.html
Copyright © 2011-2022 走看看