EntityFramework gives IDisposable error - entity-framework

I use EF for the back-end DataLayer in my asp.net websites. I create a class library and add the Model in it, reference it and use it from the ASP.NET Website. But this time, I generated the model from database but it seems does not implement IDisposable, and the methods I used to see are not there. DeleteObject , SaveChanges etc. There are only Two tables in the DB and the Model was generated with only the TableSets and two methods AddToTableSet ... Had anybody encountered such a problem?
alt text http://techlipse.net/EF-problem.jpg

Did you extend the generated ObjectContext and then perhaps rename it in the EDMX? You might be looking at your part of the partial class here without the generated part.
What does the Properties panel say for your EDMX for "Entity Container Name"?
When you right click on Entities and go to definition do you get to the correct generated class?
And lastly, but probably most likely, did you perhaps delete the Reference to System.Data.Entity from the project or not reference it in your web project?
Is you web project even a Web Application project???

I have my Entity Framework code in its own project, and was referencing it from a separate project. NuGet sets EntityFramework only on the EF project, which is how the reference gets automatically configured to the latest version. To fix this error:
Tools -> Library Package Manager -> Manage Nuget Packages for Solution
Select Installed Packages and find Entity Framework
Click the Manage Button, and check all the project that will be accessing the EF Data Model.

Related

Update model from database not updating metadata

My project has stopped updating the metadata when I add new tables or stored procedures. Its on Visual Studio 2017. with .net framework 4.6.1
I use the Update model from database wizard and after selecting the new item and clicking finish. If I check in the model browser i can see the new classes in the Model and in the model.store. Also, Its in the solution explorer .edmx.
The problem is not all projects can reference the new items and i noticed the new items are not in the Entities Metadata.
Things i tried
Run custom tools on .tt files
clean all projects individually and rebuilt
closed application and open it
Please help
I have the entity framework (DB) in a separate project the is linked in the references. I found the only thing that worked for me was to unlink the reference, rebuild and have it fail and re link the project. SOOOO frustrating as this functionality used to work quite well.

Error building Repository in a seprate project(library) within the same solution

So, I was following this Link
to learn and implement Repository pattern in my solution which consisted of a single project.
But my senior told me this is not the way we usually use and the repository is referenced from a different way(not withing the project). Using a class library, adding it to the solution and then referencing it.
When I tried doing it that way I am getting error.
Error Image
I had shifted my repository interface, class and UnitOfwork class to the library class within the same solution(As a different project)
I have even tried adding references to assembly using nuget
as shown in this question
Link
And where is Your dbContext?
Check namespace of StudentsDemoEntities, and check if repository project referenced project with context.
Then add using statment for dbContext.
Edit
Your repository can't "see" dbContext.
Move Your context to repository project and this error will be resolved.
Remember about namespace!

Can't configure Entity Data Source to work with Entity Framework 6

I'm trying to use Entity Data Source Control to access my database first Entity Framework model but I can't get it to work with Entity framework 6. It gives me an error saying its not compatible with Entity Framework 6 and instead directed me to install Microsoft.AspNet.EntityDataSource from Nuget which I've done. but for some reason I can't configure it using the wizard. In design view, it doesn't show the little arrow to open the smart tasks panel.
I'm new to ASP.NET and don't know how to configure it in markup view
which data source (or perhaps another technique) should I use to access data objects in Entity Framework 6?
I don't think you can use the wizard to configure EF6 EntiyDataSourceControl. The wizard only works with EF5. You need to configure the EF6 EntityDataSourceControl in code. Here is a corresponding ticket.
I have gone through same situation as yours.Finally this solved the issue,
Uninstalled EF6 and installed version 5 of Entity Framework through Nuget Package Manager Console, then it worked fine

Assembly references across projects - need for more than one Entity Framework reference?

For the sake of the question, I have a project structured as follows, where each layer maps to a project in my visual studio solution:
Presentation Layer
Business Logic Layer
Data Layer (working with Entity Framework)
I have repository classes defined in my Data Layer. Upon instancing them in the BL layer, I get an error stating that a reference to the entity framework assembly is missing. I add a reference to the same entity framework dll that is being used in my DL and it works.
My question is: why is it not sufficient to have the BL reference the DL, why do I still need to add an "additional" reference to EF in the BL ? I obviously do not want to control more than one EF version in my solution.
I would think my DL is an "atomic" unit, all its objects are self contained and need nothing else to function properly. Why then upon instancing classes defined in the DL would I still need to add a EF reference, what with the DL's own EF reference ?
This is indeed how the build engine MSBuild works. Visual Studio used to not complain about indirect references, only to found out at the TFS build server that it broke. As to why they build this the way they did, I do not have an answer.
I do have an easy fix:
Use solution-level NuGet packages. You add the Entity Framework package to the solution as a NuGet package, and you check all the projects that should have this reference. This way also prevents multiple different versions.
For a detailed explanation, you can read this article.

cannot debug into my DbContext derived class code using Entity Framework (ver 4.3.1) code-first

Here is my solution setup using VS 2012 Ultimate:
I have a project (e.g. MyDomainModel) containing all the business domain types using POCO classes. I have another project (e.g. MyEntity) referring to the MyDomainModel project and has the derived DbContext class (e.g. MyDbContext) implementing custom business logic (e.g. for automatic time-stamping when inserting and modifying data) in the SaveChanges method.
I have another mstest based project (e.g. MyEntity_Tests) which will test the derived DbContext (e.g. MyDbContext) with known seeded data as part of the database initialization.
My problem is that when debugging the test, the breakpoint set on the MyDbContext's c# code is not hit. However if I put lines such as Debug.Print("xxx") in the file and debugging the same test, the test output will contain those expected output "xxx".
I know that Entity Framework runtime will generate proxy dll behind scene to wrap those dlls (e.g. MyDomainModel.dll). However not being able to debug my own code as in MyDbContext is really a big problem to me. Do other people have the similar problem when using EF code-first and how to solve this problem?
Set the breakpoint on a line in the derived DbContext class start debugging and hover the mouse over it to see why it is not hit. Most likely symbols are not loaded. When debugging go to loaded modules window right click on your assembly and you can check where VS tried loading symbols from. You can also load your symbols manually. Note that if symbols don't match the assembly you need to rebuild your project to get up-to-date symbols. Another reason why a breakpoint is not hit may be because your source code does not match the assembly. You can uncheck the checkbox in Settings->Debugging to enable debugging on sources that don't match assemblies but debugging like this is painful and counter-productive. Again rebuilding should help. I am assuming you are trying debugging Debug versions of your assemblies and not Release ones.