使用Repository模式时用静态方法(static)还是实例方法

使用Repository模式时用,我常考虑到底是用静态方法(static)还是实例方法,我是用C#开发系统的,搜罗了一下,没找的有说服力的,自己决定了,等待验证

我开发c/s winform胖客户端系统时采用static,代码都的客户都运行,很少使用多线程,有没有公共的变量在多个方法中使用,自认为没啥问题。

好像大部分的系统都使用的实例方法

 

 /// <summary>
    /// 产品管理
    /// </summary>
    public class ProductRepository
    {
        public static Product GetById(int id)
        {
            var sqlstr = "select * from dbo.Product where Product_ID=@id";
            using (var conn = Database.DbService())
            {
                return conn.Query<Product>(sqlstr, new { id }).Single();
            }
        }
 
        public static void Delete(int id)
        {
 
        }
 
        public static bool Exists(string no)
        {
            return false;
        }
    } public class Product
    {
        #region Fields
        private int _product_id;
        private int _parent_id;
        private string _product_no = "";
        private string _product_name = "";
        private string _product_type = "";
        private string _remark = "";
        private string _creater = "";
        private DateTime _create_date;
        private string _data_availability = "";
        #endregion
 
        #region Public Properties
 
        public int Product_ID
        {
            get { return _product_id; }
            set
            {
                _product_id = value;
            }
        }
 
        public int Parent_ID
        {
            get { return _parent_id; }
            set
            {
                _parent_id = value;
            }
        }
 
        public string Product_No
        {
            get { return _product_no; }
            set
            {
                _product_no = value;
            }
        }
 
        public string Product_Name
        {
            get { return _product_name; }
            set
            {
                _product_name = value;
            }
        }
 
        public string Product_Type
        {
            get { return _product_type; }
            set
            {
                _product_type = value;
            }
        }
 
        public string Remark
        {
            get { return _remark; }
            set
            {
                _remark = value;
            }
        }
 
        public string Creater
        {
            get { return _creater; }
            set
            {
                _creater = value;
            }
        }
 
        public DateTime Create_Date
        {
            get { return _create_date; }
            set
            {
                _create_date = value;
            }
        }
      
 
        #endregion
                  }


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值