美文网首页EF
EF写sql语句

EF写sql语句

作者: 落地成佛 | 来源:发表于2018-02-08 17:44 被阅读38次

    查询

    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"); 
    }
    

    相关文章

      网友评论

        本文标题:EF写sql语句

        本文链接:https://www.haomeiwen.com/subject/ngnttftx.html