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',而不是文件所在的位置。 –