2013-11-24 55 views
0

我有幾個叫做RogData的類庫,它有一個DB上下文類,而RogModleEntities存儲了我所有的實體類。我需要從我的RogData庫引用RogModleEntities庫,我也添加了一個引用。我也在RogContext類的show中使用了RogModelEntities的聲明。無法從另一個庫中引用另一個類庫

在執行Stackoverflow上的每個已知修復之後,我仍然收到編譯錯誤「找不到類型名稱空間'某些類名'(是否缺少使用指令或程序集引用)」。

這是RogData庫中的DbContext類:

using System.Data.Entity; 
using RogModelEntities; 

namespace RogData 
{ 
    public class RogContext : DbContext 
    { 
     public DbSet<Person> User { get; set; } 
     public DbSet<CurrentAddress> UserAddress { get; set; } 
    } 
} 

enter image description here

而且這是兩個實體類從RogModleEntities:

namespace RogModelEntities.Models 
{ 
    public class Person 
    { 
     public int PersonID { get; set; } 
     public string FirstName { get; set; } 
     public string LastName { get; set; } 

     public virtual CurrentAddress CurrentAddress { get; set; } 

     public string PersonFullName 
     { 
      get { return LastName + ", " + FirstName; } 
     } 
    } 
} 

namespace RogModelEntities.Models 
{ 
    public class CurrentAddress 
    { 
     [Key] 
     [ForeignKey("PersonAddress")] 
     public int PersonID { get; set; } 
     public string StreetAddress { get; set; } 
     public string City { get; set; } 
     public string State { get; set; } 
     public string ZipCode { get; set; } 

     public Person PersonAddress { get; set; } 
    } 
} 
+3

它應該是'使用RogModelEntities.Models;' –

+0

@Khanh Wow ...我從來沒有想過,但我仍然想知道爲什麼因爲我的實體類不在「模型」文件夾? – Shawn

+2

重要的是'命名空間RogModelEntities.Models',而不是文件所在的位置。 –

回答

1

正如@gldraphael建議,我發佈作爲答案。

替換:

using RogModelEntities; 

有了:

using RogModelEntities.Models 

因爲你的實體都在裏面RogModelEntities.Models。重要的是聲明名稱空間的代碼:namespace RogModelEntities.Models,而不是文件所在的位置。