我遇到了一个老问题,但我在这里找不到正确的答案。
任何人都能告诉我答案吗?
using System;
using System.Linq;
using System.Collections.Generic;
using System.Web;
using System.Web.Mvc;
using System.Data;
using System.Data.Entity;
using MvcApplication1.Models;
public ActionResult Edit(int id)
{
//return View();
var maintableToEdit = (from m in _DB.mainTable where m.Id = id select m).First();
return View(maintableToEdit);
}
错误1无法将lambda表达式转换为' string'因为它不是委托类型C:\ Users \ Administrator \ Documents \ Visual Studio 2008 \ Projects \ localhost \ MvcApplication1 \ Controllers \ HomeController.cs 80 60 MvcApplication1
错误3' MvcApplication1.Models.mainTable'不包含' Id'的定义没有延伸方法' Id'接受类型' MvcApplication1.Models.mainTable'的第一个参数。可以找到(您是否缺少using指令或程序集引用?)C:\ Users \ Administrator \ Documents \ Visual Studio 2008 \ Projects \ localhost \ MvcApplication1 \ Controllers \ HomeController.cs 81 68 MvcApplication1
非常感谢!!
答案 0 :(得分:3)
使用equality (==
)运算符代替assignment (=
):
var maintableToEdit = (from m in _DB.mainTable where m.Id == id select m).First();
或者为了简洁起见:
var maintableToEdit = _DB.mainTable.First(m => m.Id == id);
答案 1 :(得分:2)
使用==
(相等运算符)代替=
(赋值运算符)。