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; }
}
}
而且这是两个实体类从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; }
}
}
它应该是'使用RogModelEntities.Models;' –
@Khanh Wow ...我从来没有想过,但我仍然想知道为什么因为我的实体类不在“模型”文件夹? – Shawn
重要的是'命名空间RogModelEntities.Models',而不是文件所在的位置。 –