0

To make data-layer be aware of my domain classes, I've added a reference between the two class libraries, HMSContext (i.e., data-layer) and Hms.Entities (i.e., domain-classes).

Following is code from HMS.Entities:

namespace HMS.Entities
{
    class Accomodation
    {
        public int ID { get; set; }
        public int AccomodationPackageID { get; set; }
        public AccomodationPackage AccomodationPackage { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
    }
}

Code from HMSContext.cs:

using System.Data.Entity;

namespace HMS.Data
{
    public class HMSContext : DbContext
    {
        public DbSet<Accomodation> Accomodations { get; set; }

    }
}

I've added a reference between these two .dlls. A snapshot showing this is attached here. For some reason, HRMContext.cs is not reading HMS.Entities despite added reference. Am I missing anything? Can someone please shed light on this. Thanks in advance.

Oxin
  • 31
  • 1
  • 7

1 Answers1

0

You are using using System.Data.Entity; where it is not related to your project structure. So add HMS.Entities too.

Any time you have such a problem, try using the full namespace and check if it is correct or not.

Note that you also have refactoring capabilities too. You can use ( Ctrl + . ) and Visual Studio helps you to use the correct namespace.

Your code has to be like this:

using System.Data.Entity;
using HMS.Entities;

namespace HMS.Data
{
    public class HMSContext : DbContext
    {
        public DbSet<Accomodation> Accomodations { get; set; }
    }
}

And for the Entity class you should use public keyword:

namespace HMS.Entities
{
    public class Accomodation
    {
        public int ID { get; set; }
        public int AccomodationPackageID { get; set; }
        public AccomodationPackage AccomodationPackage { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
    }
}
Reza Heidari
  • 1,192
  • 2
  • 18
  • 23