asp.net EF框架执行原生SQL语句

1.执行无参数sql:

string sql = "select * from IntegralInfo where convert(nvarchar,getdate(),23)='{0}' and status=1 and userinfoid='{1}'";
sql = string.Format(sql, DateTime.Now.ToString("yyyy-MM-dd"), uid);
var IntegralInfoObj = db.Database.SqlQuery<IntegralInfo>(sql).FirstOrDefault();

2.执行有参数sql:

 var IntegralInfoObj = db.Database.SqlQuery<IntegralInfo>("select * from IntegralInfo where convert(nvarchar,getdate(),23)=@time and status=1 and userinfoid=@uid", new SqlParameter("@time", DateTime.Now.ToString("yyyy-MM-dd")), new SqlParameter("@uid", uid)).FirstOrDefault();
上一篇:Tomcat不能访问ln -s软连接文件夹的前因后果


下一篇:boostrap-非常好用但是容易让人忽略的地方------clearfix