[英]Why does this IQueryable issue give me an error?
我无法弄清楚为什么下面的代码不起作用。 它导致构建错误:
IQueryable<InventoryTbl>' does not contain a definition for 'FirstOrDefault' and the best extension method overload 'Queryable.FirstOrDefault<AdminModel>(IQueryable<Admin>)
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using RuciyanaSweets.Models;
[HttpGet]
public ActionResult AdminAddorEdit(int id = 0)
{
if (id==0)
return View(new Model());
else
{
using (Entities db = new Entities ())
{
return View(db.TableName.Where(x => x.FieldID == id).FirstOrDefault< Model >());
}
}
}
TSource FirstOrDefault<TSource>(this IQueryable<TSource> source)
是System.Linq
命名空间的一部分。 检查您的项目是否引用了System.Core
,并且您using System.Linq;
并using System.Data.Entity;
.EntityFramework
package。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.