How can I execute multiple SQL commands at one time with Entity Framework?

后端 未结 2 1358
渐次进展
渐次进展 2021-01-26 07:29

I have the following code:

var sql = System.IO.File.ReadAllText(\"data_tables.sql\");
context.Database.ExecuteSqlCommand(sql);

My data_tables.s

2条回答
  •  星月不相逢
    2021-01-26 07:59

    You can use EntityFramework.Extended to achieve this using the .Future queries.

    // build up queries
    var q1 = db.Users
        .Where(t => t.EmailAddress == "one@test.com")
        .Future();
    
    var q2 = db.Tasks
        .Where(t => t.Summary == "Test")
        .Future();
    
    // this triggers the loading of all the future queries
    var users = q1.ToList();
    

提交回复
热议问题