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.

1
  • for starters, you are missing using HMS.Entities Commented May 3, 2022 at 17:53

1 Answer 1

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; }
    }
}
Sign up to request clarification or add additional context in comments.

5 Comments

while typing using HMS.Entities this error is showing up
@Oxin you forgot public keyword.
btw, without using System.Data.Entity, how will HMSContext inherit from DbContext?
True that. I added public keyword to Accomodation class and problem has resolved. Thank You Sir.
@Oxin just keep using System.Data.Entity and add your entity's namespace.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.