I am using Entity Framework 6.1 version.
I am performing insertion operation on DB.I am planning to insert a list of rows into Db.
Can anyone suggest the best way,as I have to insert bulk records into Db.
Here is my Code:
public void InsertData(List<TimingModel> modelList)
{
foreach (var model in modelList)
{
_dbContext.dbSet.Add(model);
}
_dbContext.SaveChanges();
}
Here is my 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; }
}
Below is my 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");
}
}
I am getting the below Exception:
Modifications to tables where a primary key column has property 'StoreGeneratedPattern' set to 'Computed' are not supported. Use 'Identity' pattern instead. Key column: 'UID'. Table: 'CodeFirstDatabaseSchema.model'.
Can anyone please suggest?