iotgateway/WalkingTec.Mvvm/WalkingTec.Mvvm.Core/Attributes/FixConnectionAttribute.cs
2021-12-14 14:10:44 +08:00

51 lines
1.7 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
namespace WalkingTec.Mvvm.Core
{
public enum DBOperationEnum { Default, Read, Write }
/// <summary>
/// 标记Controller或Action使用固定的连接字符串不受其他设定控制
/// </summary>
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false)]
public class FixConnectionAttribute : Attribute
{
/// <summary>
/// 连接字符串名称
/// </summary>
public string CsName { get; set; }
public DBTypeEnum? DbType { get; set; }
/// <summary>
/// 操作类型,读或写
/// </summary>
public DBOperationEnum Operation { get; set; }
/// <summary>
/// 新建固定连接字符串标记
/// </summary>
/// <param name="Operation">Operation</param>
/// <param name="CsName">the key of the ConnectionString in appsettings</param>
public FixConnectionAttribute(DBOperationEnum Operation = DBOperationEnum.Default, string CsName = "")
{
this.CsName = CsName;
this.Operation = Operation;
this.DbType = null;
}
/// <summary>
/// 操作类型,读或写
/// </summary>
/// <param name="DbType">the database type, if t is Default, the value in appsettings will be used</param>
/// <param name="Operation">Operation</param>
/// <param name="CsName">the key of the ConnectionString in appsettings</param>
public FixConnectionAttribute(DBTypeEnum DbType, DBOperationEnum Operation = DBOperationEnum.Default, string CsName = "")
{
this.CsName = CsName;
this.Operation = Operation;
this.DbType = DbType;
}
}
}