我可能真的忽略了一些东西,但是当使用 Linq to Entities linq 语句创建类时,智能感知中缺少 Select 方法!
我正在使用带有 EntityFrameWork 6.0.2 的 Visual Studio 2013。
我有以下代码片段,智能感知中下一个最接近的方法是 RemoveRange 和 SingleAsync。 中间是我应该找到 Select 的地方!
我想从 Ratings 类中获取属性的子集,而不是全部。
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Threading.Tasks;
using AjaxCallModel;
using AjaxCallModel.ViewModels;
namespace WcfServiceLibraryAjaxCall
{
public class AjaxCall : IAjaxCall
{
public async Task<List<Rating>> SelectRatingsAsync()
{
try
{
using (BillYeagerEntities DbContext = new BillYeagerEntities())
{
DbContext.Configuration.ProxyCreationEnabled = false;
DbContext.Database.Connection.Open();
var ratings = await DbContext.Ratings.ToListAsync();
return ratings;
}
}
catch (Exception ex)
{
throw;
}
}
如果我将它与我的另一个项目进行比较,则没有问题(请参阅下面的代码)。
有人知道我做错了什么或遗漏了什么吗?
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Transactions;
using YeagerTechModel;
using YeagerTechModel.DropDownLists;
using YeagerTechModel.ViewModels;
using System.Data.Entity;
using System.Threading.Tasks;
public async Task<List<ProjectName>> GetProjectNameDropDownListAsync()
{
try
{
using (YeagerTechEntities DbContext = new YeagerTechEntities())
{
DbContext.Configuration.ProxyCreationEnabled = false;
DbContext.Database.Connection.Open();
var project = await DbContext.Projects.Select(s =>
new ProjectName()
{
ProjectID = s.ProjectID,
Name = s.Name
}).ToListAsync();
return project;
}
}
catch (Exception)
{
throw;
}
}
最佳答案
将命名空间 System.Linq 添加到您的 cs 文件
使用 System.Linq;
关于c# - 使用 Linq 语句从 intellisense 中选择缺少的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20691278/