如何使用不同的 ObjectContext 提高 Entityframework ExecuteSqlCommand()



我们正在使用Service Fabric Actor 应用程序,因为我们有多个参与者。 如果我想更新 10 条记录,每条记录的行为就像不同的单个 instance.so 当我们插入它时,每次都会创建新的对象上下文。 所以我们不把缓存数据存储在上下文级别。 所以我的数据模型就像

public class StudentData {
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public String StudentId { set; get; }
public string StudentName {get;set;}
public String StudentAge { set; get; }
public string StudentDob {get;set;}
public String StudentSTD { set; get; }
public string StudentEmail {get;set;}
public String StudentAddress { set; get; }
public string StudentReligion {get;set;}

}

当我们想要更新 10 个学生时,将创建 10 个对象实例。 因此,对于每个实例,它将调用以下方法。 所以下面的方法将调用 10 次作为不同的实例 ID。

public async Update(){
using(var context = new DatabaseContext()){
context.InfoObjectDatas.Attach(studentObj);
context.Entry(studentObj).State = System.Data.Entity.EntityState.Modified;
await context.SaveChangesAsync();
} }

我们正在使用Service Fabric Actor应用程序,因为我们有多个Actor。 如果我想插入 10 条记录,每条记录的行为就像不同的单个 instance.so 当我们插入时,每次都会创建新的 ObjectContext。 所以我们不将缓存数据存储在上下文级别。 所以我的数据模型就像

public class StudentData {
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public String StudentId { set; get; }
public string StudentName {get;set;}
public String StudentAge { set; get; }
public string StudentDob {get;set;}
public String StudentSTD { set; get; }
public string StudentEmail {get;set;}
public String StudentAddress { set; get; }
public string StudentReligion {get;set;}

}

当我们想要插入 10 个学生时,将创建 10 个对象实例。 因此,对于每个实例,它将调用. 所以我对 10 个对象使用 like for 循环。

public async insert(){
using(var context = new DatabaseContext()){
Student st=new Student();
context.StudentData.Add(st);
context.StudentData.SaveChanges();
} }

最新更新