Shawn
Shawn

Reputation: 509

Unable to reference another class library from within another library

I have a couple of class libraries called RogData that has a DB context class, and RogModleEntities that stores all of my entity classes. I need to reference from my RogData library the RogModleEntities library which I added a reference too. I also have a using statement for RogModelEntities within the RogContext class show below.

After performing every known fix on Stackoverflow I'm still recieving this compile error "The type namespace 'some class name' could not be found (are you missing a using directive or assembly reference)".

This is the DBcontext class from RogData library:

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

And these are the two entity classes from 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; }
    }
}

Upvotes: 0

Views: 235

Answers (1)

Khanh TO
Khanh TO

Reputation: 48972

As suggested by @gldraphael, I post as an answer.

Replace:

using RogModelEntities;

With:

using RogModelEntities.Models

Because your entities are inside RogModelEntities.Models. What matters is the code to declare the namespace: namespace RogModelEntities.Models, not where the files are located.

Upvotes: 1

Related Questions