我正在开发一个Windows Phone 7应用程序,我想自动增加使用代码优先技术创建的数据库值。 我尝试了以下逻辑来完成此操作,但它导致异常“方法计数不受支持”
var c = new AccountEntryModel();
Expense exp = new Expense();
if (c.Expenses.Count() == 0)
exp.ExpenseId = 1;
else
exp.ExpenseId = c.Expenses.Max<Expense>(b => b.ExpenseId) + 1;
ExpenseIdTextBox.Text = exp.ExpenseId.ToString();
答案 0 :(得分:0)
我尝试了你的代码,它在Windows Phone 7.1中运行良好
以下是我的尝试:
var c = new AccountEntryModel();
Expense exp = new Expense();
if (c.Expenses.Count() == 0)
exp.ExpenseId = 1;
else
exp.ExpenseId = c.Expenses.Max<Expense>(b => b.ExpenseId) + 1;
以下是我根据您的代码在我的假设中创建的类:
public class Expense
{
public int ExpenseId { get; set;}
}
public class AccountEntryModel
{
public AccountEntryModel()
{
Expenses = new List<Expense>();
for (int i = 1; i < 10; i++)
{
Expenses.Add(new Expense { ExpenseId = i });
}
}
public List<Expense> Expenses { get; set;}
}