3

I have used Entity Framework for DAL in a few projects but in the one I'm working on right now, I have the edmx file in a class library project and that's all there is in the project. I have this project referenced in another class library project and for some reason I'm not able to access any of the entity classes that are defined in the .designer.cs file. I can't access the context class either. If i look at the referenced project in Object viewer in visual studio, it does not list any entities for this project.

Does anyone know why I'm not able to access the entity classes or the datacontext in another project?

EDIT: If it makes any difference, it's associated with a database on sql azure.

5 Answers 5

1

This is can happen into two different ways. One is to make sure the Entity Model class are public. The other is to check the Entity Model Namespace is matches to the Context class.

Sign up to request clarification or add additional context in comments.

1 Comment

All the entity classes are public.And it's not the namespace either. Even if i created a class inside the designer.cs right below an entity class, I still cannot access that entity or context from there. I even tried refreshing and updating the edmx file.
1

I was able to resolve it by deleting the existing edmx file and regenerating a new one.

Apparently the old one got into a weird state, I was not able to figure out how to get it to work again.

Comments

1

I have used Entity Framework for DAL in a few projects but in the one I'm working on right now, I have the edmx file in a class library project and that's all there is in the project. I have this project referenced in another class library project where i was not able to initialize the object for the entity class saying connection string was not set ,where i have checke with the connection string which was there.\

Comments

1

check your inherited class of DbContext, it must be public

1 Comment

Also, you can add the attribute to namespace that you want it be visible: [assembly: InternalsVisibleTo("ProyectName or namespace")]. You need aggregate using directive: using System.Runtime.CompilerServices; for example: using System.Data.Entity; using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("OtherProyect")] namespace Persistence.DAL.EntityFramework { internal class HotelContext:DbContext { // code } }
0

Check the Namespaces of the Context class and Designer.cs class.

2 Comments

Nope. it's not the namespace. Even if i created a class inside the designer.cs right below an entity class, I still cannot access that entity or context from there. I even tried refreshing and updating the edmx file.
Make sure the namespace and the context class name is not the same.

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.