2011-01-24 58 views
2
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。有没有人有任何好主意?找不到ObjectSet库?

回答

3

确保您的项目有对System.Data.Entity的参考。

您可能还需要参考System.Runtime.SerializationSystem.Security

当您向项目添加EDMX文件(ADO.NET实体数据模型)时,Visual Studio会自动为您添加这些内容。

+1

明白了..这是由于某种原因使用.net 3.5 ..我的坏:( – Vishal 2011-01-24 21:04:43