using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using ModelLayer.PocoModels;
using System.Data.Objects;
namespace ModelLayer
{
public class NorthwindDataContext : ObjectContext
{
private ObjectSet<Category> _categories;
private ObjectSet<Product> _products;
public NorthwindDataContext()
: base("name=NorthwindEntities",
"NorthwindEntities")
{
_categories = CreateObjectSet<Category>();
_products = CreateObjectSet<Product>();
}
}
}在上面的代码中,我得到了一个错误,因为它找不到ObjectSet类,并给出了在示例项目中找不到error.While的类型或名称空间。它工作得很好,它是在使用System.Data.Objects.ObjectSet下运行的,但我在当前项目中看不到该库?我使用的是asp.net mvc和.net 4.0。有人有什么好主意吗?
发布于 2011-01-25 04:58:45
确保您的项目具有对System.Data.Entity的引用。
您可能还需要引用System.Runtime.Serialization和System.Security。
Visual Studio会在您向项目中添加EDMX文件(ADO.NET实体数据模型)时自动为您添加这些文件。
https://stackoverflow.com/questions/4787065
复制相似问题