EF写sql语句

查询

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

修改

using (var context = new BloggingContext()) 
{ 
    context.Database.ExecuteSqlCommand( 
        "UPDATE dbo.Blogs SET Name = 'Another Name' WHERE BlogId = 1"); 
}

你可能感兴趣的:(EF写sql语句)