解决方案 »

  1.   

    那些叫特性  你可以搜索一下:C# 特性(Attribute)
    DBField 的作用 你可以搜索一下CodeFirst 应该和它相关
      

  2.   


    比如:[DbField(true, "event_id")]
           public int Id { get; set; }
    数据库中查询出来的是event_id,会自动对应到我们定义的实体,属性ID上。
      

  3.   

    加了一个新类,怎么敲不出来的。
    :[DbField(true, "event_id")]
      

  4.   

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;namespace SXT.Sample.Web.Admin.Project.SystemDemo.Model
    {
        public class Class1
        {
           
        }
    }
      

  5.   

    第一个 不要清楚第二个是声明该属性可为NULL值吧
      

  6.   

    [DbField(true, "event_id")]Attribute,如果你听说过metaprogramming,你就会明白这大体是个什么意思。简单来讲,程序中的其他对象可以通过reflection获取你给DbField设置的值(true and "event_id")。
      

  7.   

    这个和meta programming没什么关系。attributes属于meta data。
      

  8.   

    问号就是可空类型啦,值类型的玩意不能直接赋值null的比如int a=null;是报错的  int? a=null;是可以的
      

  9.   

     [AttributeUsage(AttributeTargets.All)]
        public class DbField : Attribute
        {
            #region 初始数据库字段属性        [Description("数据库对应字段信息")]
            public DbField(bool _useable)
            {
                this.FieldName = string.Empty;
                this.FieldType = typeof(string);
                this.Primary = false;
                this.Identity = false;
                this.MaxLength = 0;
                this.Useable = _useable;
            }        [Description("数据库对应字段信息")]
            public DbField(bool _useable, string _name)
            {
                this.FieldName = _name;
                this.FieldType = typeof(string);
                this.Primary = false;
                this.Identity = false;
                this.MaxLength = 0;
                this.Useable = _useable;
            }
            #endregion.        /// <summary>
            /// 对应数据库字段名称
            /// </summary>
            public string FieldName { get; private set; }        /// <summary>
            /// 字段类型
            /// </summary>
            public Type FieldType { get; private set; }        /// <summary>
            /// 默认信息值
            /// </summary>
            public bool Primary { get; set; }        /// <summary>
            /// 自增键值
            /// </summary>
            public bool Identity { get; set; }        /// <summary>
            /// 字符串最大长度
            /// </summary>
            public int MaxLength { get; set; }        /// <summary>
            /// 是否可用于数据更新或绑定数据。
            /// </summary>
            public bool Useable { get; set; }        /// <summary>
            /// 是否ENCODEURL
            /// </summary>
            public bool Encode { get; set; }
        }