EF写sql语句

查询

using (var context = new BloggingContext()) 
{ 
    var blogNames = context.Database.SqlQuery<string>( 
                       "SELECT Name FROM dbo.Blogs").ToList(); 
}

修改

using (var context = new BloggingContext()) 
{ 
    context.Database.ExecuteSqlCommand( 
        "UPDATE dbo.Blogs SET Name = 'Another Name' WHERE BlogId = 1"); 
}
    原文作者:落地成佛
    原文地址: https://www.jianshu.com/p/4715009e8a53
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞