我第一次使用Entity Framework,但它似乎没有像预期的那样工作。
这是我的代码:
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
public static class QueryClass
{
public static void Query()
{
using (var context = new MyDbEntities())
{
DbSet<MyTable> set = context.Tables;
var query = from val in set select value;
}
}
}
在查询行上(即红色下划线正好在“set”变量上方),我遇到以下错误:
找不到“System.Data.Entity.DbSet”的源类型的查询模式实现。 找不到“Select”。缺少对“System.Linq”的引用或使用指令
MyDbEntities
是通过 Entity Framework 在 Database-First 方法中自动生成的,context.Tables
是一个 DbSet
,因此应该能够使用 Linq,通过 using
指令添加。为了避免误解,我在这个类中找到了以下内容:
public virtual DbSet<MyTable> Tables { get; set; }
我需要做什么才能让select
起作用?
谢谢。