救命 !!如何更新具有int数据类型的记录 [英] help !! how to update record having int data type
问题描述
public void upd()
{
amritEntities context = new amritEntities();
IEnumerable< timesheet> list = 来自 v in context.Timesheets
其中 v.projectid = 5
select v;
foreach ( var v in list)
{
v.projectid = Convert.ToInt32( 5 + 2 );
}
context.SaveChanges();
}
}
}
构建时出错
< pre lang =text>错误1无法将lambda表达式转换为类型'string',因为它不是委托类型C:\ Users \ user \ docs \ visual studio 2010 \Projects\ConsoleApplication49 \ConsoleApplication49 \ Class3.cs 15 43 ConsoleApplication49
错误3无法隐式转换类型'int?' to'bool'C:\ Users\user \documents\visual studio 2010 \Projects\ConsoleApplication49\ConsoleApplication49\Class3.cs 15 49 ConsoleApplication49
错误2委托'System.Func< ConsoleApplication49 .Timesheet,INT,布尔>不带1个参数C:\ Users \ user \documents \ visual studio 2010 \Projects\ConsoleApplication49 \ConsoleApplication49 \Class3.cs 15 43 ConsoleApplication49
1.您必须使用与您的属性相同类型的常量值Timesheets
实体类应该是;
2.因此,您必须查看Timesheets
类的生成源代码,了解该属性projectid
,如果其类型为string
,则应在代码中使用字符串值,如下例所示:
IEnumerable< timesheet> list = 来自 v in context.Timesheets
其中 v.projectid = 5
选择 v;
< / 时间表 >
3.基于projectid
是一个int的信息您应该像这样更改您的代码:
public void upd()
{
amritEntities amritEntities context = new amritEntities()
//
// 建立您的查询
IQueryable< timesheet> list = 来自 v in context.Timesheets
其中 v.projectid = 5
select v;
//
// 运行查询==>结果
列表< timesheet> resultList = list.ToList();
//
// 修改ID。
foreach (时间表项 in resultList)
{
item.projectid = 7 ;
}
//
// 保存更改
context.SaveChanges();
}
}
public void upd()
{
amritEntities context = new amritEntities();
IEnumerable<timesheet> list = from v in context.Timesheets
where v.projectid = 5
select v;
foreach (var v in list)
{
v.projectid = Convert.ToInt32(5 + 2);
}
context.SaveChanges();
}
}
}
errors while build
Error 1 Cannot convert lambda expression to type 'string' because it is not a delegate type C:\Users\user\documents\visual studio 2010\Projects\ConsoleApplication49\ConsoleApplication49\Class3.cs 15 43 ConsoleApplication49
Error 3 Cannot implicitly convert type 'int?' to 'bool' C:\Users\user\documents\visual studio 2010\Projects\ConsoleApplication49\ConsoleApplication49\Class3.cs 15 49 ConsoleApplication49
Error 2 Delegate 'System.Func<ConsoleApplication49.Timesheet,int,bool>' does not take 1 arguments C:\Users\user\documents\visual studio 2010\Projects\ConsoleApplication49\ConsoleApplication49\Class3.cs 15 43 ConsoleApplication49
1.You must use constants values from the same type as your properties fromTimesheets
entity class are expected to be;
2.So you have to look on the generated source code of yourTimesheets
class for the propertyprojectid
, and if its type isstring
you should use string values in your code like in the next example:
IEnumerable<timesheet> list = from v in context.Timesheets where v.projectid = "5" select v; </timesheet>
3.Based on the info that yourprojectid
is an int you should change your code like this:
public void upd() { amritEntities amritEntities context = new amritEntities() // //Build your query IQueryable<timesheet> list = from v in context.Timesheets where v.projectid = 5 select v; // // Run the query ==> the results List<timesheet> resultList = list.ToList(); // //Modify the IDs. foreach (timesheet item in resultList ) { item.projectid = 7; } // //Save the changes context.SaveChanges(); } }
这篇关于救命 !!如何更新具有int数据类型的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!