当前位置: 代码迷 >> ASP.NET >> linq增添数据 报 当 IDENTITY_INSERT 设置为 OFF 时,不能为表 'bx_wap_TypeInfo' 中的标识列插入显式值
  详细解决方案

linq增添数据 报 当 IDENTITY_INSERT 设置为 OFF 时,不能为表 'bx_wap_TypeInfo' 中的标识列插入显式值

热度:6466   发布时间:2013-02-25 00:00:00.0
linq添加数据 报 当 IDENTITY_INSERT 设置为 OFF 时,不能为表 'bx_wap_TypeInfo' 中的标识列插入显式值。
错误:

C# code
当 IDENTITY_INSERT 设置为 OFF 时,不能为表 'bx_wap_TypeInfo' 中的标识列插入显式值。 说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.SqlClient.SqlException: 当 IDENTITY_INSERT 设置为 OFF 时,不能为表 'bx_wap_TypeInfo' 中的标识列插入显式值。源错误: 行 54:             ti.memo = memo.Text.Trim();行 55:             table.InsertOnSubmit(ti);行 56:             dc.SubmitChanges();行 57:             string CacheName = SiteConfig.PrefixName + dc.Mapping.GetTable(typeof(bx_wap_TypeInfo)).TableName;行 58:             IXinHuaCache cache = XinHuaCache.Instance(); 


添加部分的代码
C# code
         DataContext dc = DataContextHelper.DataContext;          Table<bx_wap_TypeInfo> table = dc.GetTable<bx_wap_TypeInfo>();            bx_wap_TypeInfo ti = new bx_wap_TypeInfo();           // ti.typeid = 0;typeid是主键未赋值            ti.typename = tbstypename.Text.Trim();            ti.typeimg = fileName;            ti.status = 0;            ti.cpid = 1;            ti.parentid =0;            ti.ctype =1;            ti.sortid = 0;            ti.memo = memo.Text.Trim();            table.InsertOnSubmit(ti);            dc.SubmitChanges();            dc.Dispose();


以下是实体代码
C# code
[Table(Name = "bx_wap_TypeInfo")]    public partial class bx_wap_TypeInfo : ModelBase    {        public bx_wap_TypeInfo()        {            //base.M_TableName = "bx_wap_TypeInfo";        }        #region Model        private int _typeid;        private string _typename;        private string _typeimg;        private int? _status = 0;        private int? _cpid = 0;        private int? _parentid = 0;        private int? _ctype = 0;        private int? _sortid = 0;        private string _memo;        private DateTime? _addtime = DateTime.Now;        private int? _totalvideo = 0;        private int? _delstatus = 0;              /// <summary>        ///         /// </summary>        [Column(IsPrimaryKey = true)]        public int typeid        {            set { _typeid = value;// base.M_PrimaryKeyID = value;             }            get { return _typeid;   }        }        [Column(Name = "typename")]        public string typename        {            set { _typename = value; }            get { return _typename; }        }        [Column(Name = "typeimg")]        public string typeimg        {            set { _typeimg = value; }            get { return _typeimg; }        }        [Column(Name = "status")]        public int? status        {            set { _status = value; }            get { return _status; }        }        [Column(Name = "cpid")]        public int? cpid        {            set { _cpid = value; }            get { return _cpid; }        }        [Column(Name = "parentid")]        public int? parentid        {            set { _parentid = value; }            get { return _parentid; }        }        [Column(Name = "ctype")]        public int? ctype        {            set { _ctype = value; }            get { return _ctype; }        }        [Column(Name = "sortid")]        public int? sortid        {            set { _sortid = value; }            get { return _sortid; }        }        [Column(Name = "memo")]        public string memo        {            set { _memo = value; }            get { return _memo; }        }        [Column(Name = "addtime")]        public DateTime? addtime        {            set { _addtime = value; }            get { return _addtime; }        }        [Column(Name = "totalvideo")]        public int? totalvideo        {            set { _totalvideo = value; }            get { return _totalvideo; }        }        [Column(Name = "delstatus")]        public int? delstatus        {            set { _delstatus = value; }            get { return _delstatus; }        }        #endregion Model    }
  相关解决方案