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;
    }
    }
    }

  • 相关阅读:
    导入测试用例的设计
    质量管理的精髓
    ios crash的原因与抓取crash日志的方法
    怎样实现excel隔行隔列变色效果的方法
    如何提高员工的质量意识?
    史上最全的测试团队组建方法
    如何写好缺陷报告?
    你还不知道?这四个因素决定了你的养老金待遇!
    各手机截屏方法收集
    利用drozer进行Android渗透测试
  • 原文地址:https://www.cnblogs.com/chengjun/p/8398872.html
Copyright © 2011-2022 走看看