c# - 使用 Linq 语句从 intellisense 中选择缺少的方法

标签 c# linq entity-framework

我可能真的忽略了一些东西,但是当使用 Linq to Entities linq 语句创建类时,智能感知中缺少 Select 方法!

我正在使用带有 EntityFrameWork 6.0.2 的 Visual Studio 2013。

我有以下代码片段,智能感知中下一个最接近的方法是 RemoveRangeSingleAsync中间是我应该找到 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/

相关文章:

c# - TuesPechkin 无法加载 DLL 'wkhtmltox.dll'

c# - 在c#中读取加密的文本文件

c# - 部署后无法登录

c# - 无法更改 CodeBehind 中 LinkBut​​ton 的属性

c# - 可以使用 Mono 使任何 ASP.net 应用程序(或其中的大部分)在 Linux 下运行吗?

c# - 解析大文本文件输出到另一个文本文件

c# - 拦截IQueryable Provider的 'Expression'属性并获取其e-sql

linq - Linq Take()问题

entity-framework - EntityFramework:如何配置级联删除以使外键无效

asp.net-mvc - (代码第一)使用非标准命名约定的 Entity Framework 外键