Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework UnintentionalCodeFirstException

I have a MVC 4 project set up and generated all the model classes using Entity Framework. Then I added a class and named it same as "MyProjectEntities" class and made it partial so I can add personalized methods in that class. I added bunch of methods to query database in this class and it builds fine. When I call these methods though I get UnintentionalCodeFirstException. I'm not sure what did I do wrong?

like image 448
DAK Avatar asked May 06 '13 20:05

DAK


People also ask

Why am I getting a connection string exception in Entity Framework?

--- Tried several versions of code in the web.config file in entity framework section with no luck. That exception is usually thrown when your connection string doesn't include the "metadata" stuff. Are you sure you haven't changed the connection string on the server?

Which class derives dbcontext in Entity Framework?

The class that derives DbContext is called context class in entity framework. DbContext is an important class in Entity Framework API. It is a bridge between your domain or entity classes and the database.

How do I use database first and model first in Entity Framework?

If you wish to use Database First or Model First, then make sure that the Entity Framework connection string is included in the app.config or web.config of the start-up project.

What is onmodelcreating method in Entity Framework 6?

The OnModelCreating method allows us to configure the model using DbModelBuilder Fluent API in EF 6. Gets an DbEntityEntry for the given entity. The entry provides access to change tracking information and operations for the entity. Executes INSERT, UPDATE and DELETE commands to the database for the entities with Added, Modified and Deleted state.


1 Answers

You need to provide the correct connection string. Not just the normal "Data Source=" type strings.

You will have a connection string that starts with "metadata=" in your config file, use that one.

like image 105
Jammer Avatar answered Sep 23 '22 03:09

Jammer