簡體   English   中英

實體框架插入Db面臨的問題

[英]Facing issue with entity framework insert to Db

我正在使用Entity Framework 6.1版本。

我正在對DB執行插入操作,我計划將行列表插入Db。

誰能建議最好的方法,因為我必須將大量記錄插入Db。

這是我的代碼:

 public void InsertData(List<TimingModel> modelList)
        {
            foreach (var model in modelList)
            {
                _dbContext.dbSet.Add(model);

            }
            _dbContext.SaveChanges();
        }

這是我的TimingModel

 public class Model
    {
       [DatabaseGenerated(DatabaseGeneratedOption.Computed)] 
        public int UID{get;set;}
        public string Application { get; set; }
        public string Service { get; set; }
        public string Call { get; set; }
        public string Verb { get; set; }
        public string API { get; set; }
        public string HttpResponse { get; set; }
        public DateTime StartTime { get; set; }
        public DateTime StopTime { get; set; }
        public int Duration { get; set; }
        public int SQLDuration { get; set; }
        public string Caller { get; set; }
        public string Nodename { get; set; }
        public string Server { get; set; }
        public string Logfile { get; set; }
        public string Product { get; set; }
        public string Session { get; set; }
        public int OrganisationUID { get; set; }
    }

以下是我的Mapper:

 public class TimingMapper: EntityTypeConfiguration<TimingModel>
    {
        public TimingMapper()
        {
            // Primary Key
            this.HasKey(n => n.UID);
           // Table & Column Mappings
            this.ToTable("Timing");

            this.Property(n => n.OrganisationUID).HasColumnName("OrgUID");

            }
    }

我收到以下異常:

不支持對主鍵列的屬性“ StoreGeneratedPattern”設置為“計算”的表進行修改。 請改用“身份”模式。 關鍵列:“ UID”。 表格:“ CodeFirstDatabaseSchema.model”。

有人可以建議嗎?

感謝您的支持。

我想出了數據庫表中的問題,列的大小較小。

增加數據庫表中列的大小后,此問題得到解決。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM