Entity Framework5如何直接执行sql语句?
请问有了解ef5的大神吗? ef5 --------------------编程问答-------------------- http://msdn.microsoft.com/en-us/library/dd487208.aspxExecuteStoreQuery --------------------编程问答-------------------- 使用ExecuteStoreCommand:这个更加灵活,你可以执行Update,Insert,Delete语句。
using (SzmbEntities entity = new SzmbEntities())
{
var item = entity.Weatherwarnings.OrderByDescending(x=>x.Id)
.Where(x => x.PublishTime < now.AddDays(-14))
.FirstOrDefault();
if (item != null)
{
string sql = "Delete FROM [Weatherwarning] where Id < @ID";
var args = new DbParameter[] {
new SqlParameter { ParameterName = "ID", Value = item.Id}
};
entity.ExecuteStoreCommand(sql,args);
}
}
ExecuteStoreCommand()返回一个int值,影响的行数。
http://www.cnblogs.com/shanyou/archive/2012/11/18/2776357.html --------------------编程问答-------------------- ExecuteStoreCommand
补充:.NET技术 , ASP.NET