我可能真的忽略了某些东西,但是当使用Linq to Entities linq语句创建一个类时,intellisense中缺少 Select 方法!
我正在使用Visual Studio 2013和EntityFrameWork 6.0.2。
我有以下代码段,智能感知中接下来最接近的方法是 RemoveRange 和 SingleAsync 。 介于两者之间我应该找到选择!
我想从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;
}
}
答案 0 :(得分:5)
Add the namespace System.Linq to your cs file
using System.Linq;