after recreate edmx no suitable method found to override - ado.net-entity-data-model

I delete edmx and create new edmx but I have two error!
Help me please!

Related

Entity Framework Core Migrate Table from DB

I'm wondering if this is even possible. I'm writing an app in MVC using ASP.NET Core and EF Core. For the most part I've been doing code-first migrations (that's all I know how to do, as yet) for my entities.
Someone added a table to the database I'm using, and rather than deleting their table and doing it the code-first way, I'd like to just bring their table over using a DB first migration.
Is that even possible to mix and match DB-first/code-first techniques?
If it is, how do I do it? I can't seem to find anything about bringing over just one table. Only migrating a whole database, which is not what I want.
Yes, it's possible. The steps are the following:
Right click on your Models folder.
Select Add -> Add new Item
In the Add New Item Window, select Data -> ADO.NET Entity Data Model. (This would create a new DbContext, but we going to merge the two DbContext) Click Add
In the Entity Data Model Wizard select Code First from database.
Select your connection String.
Click in no, exclude sensitive data...
Uncheck Save connection settings.
Click next
Select the new Table
Click finish
In this point VS would generate two files: a new DbContext and the model for the table.
Now open de new DbContext cut the DbSet of your model and paste in your original DBContext, too cut the content of the OnModelCreating method and paste at the end of the OnModelCreating method of your Original DbContext.
The final step is add a new Migration ignoring the changes.
For example:
Add-migration NewTableAdded -IgnoreChanges -verbose

Entity Framework Multiple EDMX file sharing same tables

Environment : EF 6, SQL 2012
Setup: Database First, LazyLoading disabled
The question might appear more generic but will try to explain it in the best possible way.
I have a large application using ASP.NET MVC and grouped the entity based on the logical functionality. Hence we built multiple EDMX files
There is scenario in which we have to use the similar entity in two EDMX file.
School has relation to Teachers and Students.In first EDMX file, i used school and Teachers.In Second EDMX file, i used school and students
But only one Entity class getting created. If i run the custom tool on second EDMX context file, then the entity(school.cs) on my first edmx getting disappeared and it appears on the second one..
Why this strange behaviour occurs?
Here is the code in my first EDMX file
As you see here, i m not accessing school entity and also i disabled Lazyloading. But it complains that it couldnt find school file. Note: Courses has navigation property to school. But i didnt include it here.. Why its occuring so?
var courses= DB.courses
.AsNoTracking()
.Select(e =>
new CourseDTO()
{
CourseID= e.CourseID,
Name= e.CourseName,
Desc= e.Desc,
isActive= e.isActive
})
.OrderBy(e => e.CourseID);
The problem is, I m able to include one entity in the EDMX file only..
In first EDMX, it has navigation property to Teachers
In second EDMX , it has navigation property related to Students. But only Entity file exists at a time.. With only one Entity file, the code breaks
Note: This is just sample..Not my original application
Thanks #GertArnold. Meanwhile, i tried to create folders and kept the EDMX file inside it. Means i created seperate folder for each logical group and then included edmx file inside it. This in turn made the edmx file entities have different name space(i mean the entity classes) and also it enabled to have the same entity across multiple EDMX files. It sounds to have resolved my problem.
I didnt try to have them included under different namespace.. The whole idea started when i realized that even though i have two EDMX files, the associated entities(.csfiles) are created in the same physical location. I tried to create sub folders and included the EDMX files. It resolved the problem and i found it is having different name space
:):)

ADO.Entity Model with simple membership tables?

I am new to both MVC and the simple membership that comes with ASP.NET.
I have been following tutorials and I have been able to create the Simple membership tables to work in a custom db along with my own tables.
I ran into a problem when I tried to use the ADO.Entity Model to create classes so i could access the database data. When i tried to run the application after creating the entity models i got an error. I think it is because the ADO.Entity Model created classes with the same name as classes all ready in the app???
Error 1 Missing partial modifier on declaration of type 'MvcApplication5.Models.UserProfile'; another partial declaration of this type exists C:\Users\user\Desktop\MvcApplication5\MvcApplication5\Models\AccountModels.cs 22 18 MvcApplication5
Any help would be greatly appreciated
Thanks
SimpleMembership uses EF code-first so you do not need to create the classes, they are already created by the T4 Internet Template. The class that represents the UserProfile exists in the file referenced in your error message. You are getting an error message because you are trying to create a duplicate of the class that already exists. Take a look at this article on how to customize SimpleMembership.

+entityForName: could not locate an entity named 'Dogs' in this model.

A little question regarding Core data models.
Here is why I'm posting : +entityForName: could not locate an entity named 'Dogs' in this model.
What I wanna do :
I wanna create an app that will read/write in core data details about animals with 2 entities Cats and Dogs.
-For that I create a window-based project with "use core data" checked.
-Then I create my views, and click on "animals.xcdatamodeld" file to create a first entity called Cats. I add the attributes, generate the class "cats.h" and "cats.m".
- I write down the code to read and write on this entity => No problem everything works well.
At this point I made a mistake by deleting the file "animals.xcdatamodeld" manually... I recreate it with the same name and add a new entity Dogs with its attributes and generate the associated class.
That's where the problem is, when I build and run the error message comes : +entityForName: could not locate an entity named 'Dogs' in this model. FYI, the read/write on Cats is still ok.
I have no idea why this error appears... I did not change anything on the App Delegate. I found very little information online related to that issue.
This only thing I found was that maybe the model needs to be versioned when updated => Can someone explain that a lil bit please ?
Anyway the model does not seem to have been updated when I added the new entity...
Thx.
Ok as expected somehow, this error was due to a stupid mistake...
The deleted xcdatamodeld file was replaced by a new one with a different spelling...
Now everything's fine...

Where is modelBuilder.IncludeMetadataInDatabase in EF CTP5?

With CTP4, I used to be able to do the following (as suggested by ptrandem):
modelBuilder.IncludeMetadataInDatabase = false
With this line of code, EF doesn't create the EdmMetadata table in my database, and doesn't track model changes.
I was unable to find a way to accomplish this in the new CTP5, so now every time I change my model, I get this:
The model backing the 'MyContext'
context has changed since the database
was created. Either manually
delete/update the database, or call
Database.SetInitializer with an
IDatabaseInitializer instance. For
example, the
DropCreateDatabaseIfModelChanges
strategy will automatically delete and
recreate the database, and optionally
seed it with new data.
So, does everybody know where is the IncludeMetadataInDatabase property in CTP5? Thanks.
CTP5 includes a very cool feature called Pluggable Conventions that can be used to Add/Remove conventions. IncludeMetadataInDatabase has been removed and being replaced with a
pluggable convention that does the same thing for you:
modelBuilder.Conventions
.Remove<System.Data.Entity.Database.IncludeMetadataConvention>();
The equivalent in CTP5 to switch off initializer logic: In your Application_Start in Global.asax, enter the following:
System.Data.Entity.Database.DbDatabase.SetInitializer<MyDBContext>(null);
In EF 4.1
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<IncludeMetadataConvention>();
}
Have been looking for this all over, and I had to find the answer right after posting my question, DUH. Right from the ADO.NET team blog:
In CTP5 we have removed the need to
perform additional configuration when
mapping to an existing database. If
Code First detects that it is pointing
to an existing database schema that it
did not create then it will ‘trust
you’ and attempt to use code first
with the schema. The easiest way to
point Code First to an existing
database is to add a App/Web.config
connection string with the same name
as your derived DbContext (...)

Resources