2013-11-24 54 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,而不是文件所在的位置。