2009-08-11 41 views
1

我剛剛拿到這本書Asp.net MVC Unleashed Generic Repostitory發生問題

其中有一個用於通用存儲庫的.dll。我跟着他做了什麼,但我總是得到一個錯誤。

System.InvalidOperationException was caught 
    Message="The EntitySet name 'MyEntities.CarSet' could not be found." 
    Source="System.Data.Entity" 
    StackTrace: 
     at System.Data.Objects.ObjectContext.GetEntitySet(String entitySetName, String entityContainerName) 
     at System.Data.Objects.ObjectContext.GetEntitySetFromName(String entitySetName) 
     at System.Data.Objects.ObjectContext.AddObject(String entitySetName, Object entity) 
     at GenericRepository.EFGenericRepository.Create[T](T entityToCreate) 
     at CarSite.com.Controllers.RController.Institutions(FormCollection regForm) in I:\p\trunk\Current Site\Controllers\RController.cs:line 227 
    InnerException: 

我不知道爲什麼我得到這個。我無法看到.dll,所以我不知道那裏發生了什麼。

我寫的其他存儲庫工作正常。這只是他的通用存儲庫。

我想我有他所期望的一切,他有一個類型化的視圖,他需要的數據庫的東西來自參數作爲一個類。

礦是一種形式,我作出這樣

Car send = new Car(); 
    send.Name= regForm["Name"]; 
    send.CarID= regForm["ID"]; 

Authenticate.repository.Create<Car>(send); 

我看不出這個影響呢?

編輯

現在我得到這個錯誤

Entities in 'Entities.CarSet' participate in the 'FK_Car_aspnet_Users' relationship. 0 related 'aspnet_Users' were found. 1 'aspnet_Users' is expected. 

我不知道如何添加到通過詮釋他的價值觀需要滿足這個關係我創建語句。

回答

0

方法EFGenericRepository.Create以某種方式猜測爲Car實體設置的實體稱爲「CarSet」。但顯然不是。因此,您可以查看該方法的代碼,以查看實體集名稱來自哪裏,或更改實體模型中爲Car設置的實體的名稱。

+0

什麼方法? GenericRepository中的那些?或者我的代碼? – chobo2 2009-08-11 19:00:05

+0

再次看看EFGenericRepository.Create。 – 2009-08-11 20:26:30

+0

嗨好吧,我想通了,現在我得到一個新的錯誤,不知道如何解決。 查看原文。 – chobo2 2009-08-13 18:54:29