Update model class name in EntityFramework - asp.net-mvc

I have one table in the database with the name "Users", a year ago one of the developers added a model using database-first approach, and I don't know which entity framework version they used.
Now i want to change some of the fields datatypes in SQL.
The problem is that I am not able to update model using the refresh window and also tried to delete model and add it again, but after that there was a name that has been changed in Users to User.
The current entity framework version is 6.1.3

Just go to your DataBase.edmx and right click "Update Model from Database..." and then refresh the tables

For the table name check link please -> What is the meaning of the "Pluralize or singularize generated object names" setting?
And Ricardo has already written the update.

Related

EF database-first approach how to add new not null column to production table and manage at code level

My ASP.NET MVC 4 application uses Entity Framework 6 and a database-first approach. It is already in production environment, and now wants to add new column to the Deposit table and this column is not null. The production table already has a lot of data.
How should I manage this changes, in code-first approach, can anyone help me out? What should I do, I am new to Entity Framework.
If you will continue to use the database-first approach you can do something like that:
1) run a script to migrate DB:
ALTER TABLE Deposit ADD <column_name> INT NULL
GO
UPDATE Deposit SET <a valid not null values for your column>
GO
ALTER TABLE Deposit ALTER COLUMN <column_name> INT NOT NULL
GO
2) Since you are using the db-first approach you need update edmx model (.edmx file) which is already attached to db. If I remember correctly, you can do it from context menu in Solution Explorer.

iOS - How to migrate 2 Entities into 1 using Core Data?

In my current model version I have this 4 Entities :
Satellite (with relationship to one to SatelliteAnimation)
SatelliteAnimation
Radar (with relationship to one to RadarAnimation)
RadarAnimation
In my App I have different blocs in which I display information.
This is why I have entities RadarAnimation and SatelliteAnimation, in order to recognize those blocs by type.
Anyway, my issue is that I want to migrate 2 blocs in 1.
And instead of having 4 Entities, I would like to have :
Radar
Satellite
Animations
I don't need the relationships anymore.
I know I can rename an Entity in a lightweight migration process.
What I would like to do is :
Create a new data model version
Delete the SatelliteAnimation entity
Delete the relationship between Satellite and SatelliteAnimation
Delete the relationship between Radar and RadarAnimation
Rename the entity RadarAnimation by Animations
Set the new data model version as current model version
Does this way of handling my issue will affect the migration process ?
Can I rename and remove relationships in a new data model version ?
This should be possible with automatic lightweight migration. Deleting entities and relationships just works with no extra steps, so that's fine.
To rename something you'll use the renaming identifier in the model editor. After you create the new version of your model, select the entity you want to rename in the model editor. Change its name but set the renaming identifier to the old name. In your case, change the entity name from RadarAnimation to Animation, but then also set the renaming identifier on the entity to RadarAnimation so Core Data knows what it used to be called.
Incidentally attributes and relationships can also have renaming identifiers, so they can also be renamed this way.
Apple provides detailed documentation on what can be done with lightweight migration which will probably be useful as you go through this.

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

Edmx File is not showing Diagram for DB first approach

I have a Database , and I am proceeding with EF DB first approach .
Right click on Model folder
--> select new item
-->ADO.net Entity Data model.
then selecting the DB & finally clicking Finish.
After that I am not getting the Model Diagram of my DB. Not getting any Diagram for any of the tables.
The Default view is ADO.net Entity Data model Designer
Where is the issue? EF version is latest Stable(6.1.3).
enter image description here
Did you select the tables?
https://magnusmontin.files.wordpress.com/2013/05/wizard2.png?w=590&h=515
Or remove ef and then later add your project
Your answer is that your current version of the asp.net web application form's entity framework does not match the entity framework version while you create your DB first model

oracle devart entity framework - added New column - now trigger system_id not changing to a unique new number?

oracle 10.4
devart dotConnect - 6.50...
MVC2 project - web page
User fills out form, then controller gets new entity, fills it out. saves database
System_id before saving = 0 (its an int/number - so no cannot be null)
Several other tables linked, so they have their own System_id as well.
When it gets saved to database, some trigger (there is a stored trigger for the table, which I only seam to understand as when system_id=null to be fired), a new Number is assigned for System_id.
This all worked fine.
Then I came along, and needed some updates.
Another field needed on this "main" table
(I have earlier, added columns to another table, with out issue)
Added column to this "main" table (restrict_to_me)
Now when it tries to save to database - it trys saving "system_id=0".
Linked tables, also make records with system_id=0
In entity framework designer - i can see the field system_id ENTITY_KEY=true and StoredGeneratedPatern=Idenity
So I can not see what I have done to stop somthing from working with the entity framework, except updating the entity framework.
Any direction much appricated
thanks
When you added the new field, did you drop the table and recreate it?
If you did that then you deleted the trigger at the same time. So when you recreate the table, you also need to recreate the trigger.
Try inserting data just using an SQL statement and see if the id is generated.
This was an Entity Framework issue, one many have already had.
Not every time, but some times, when updating the model, StoredGenereatedPattern being droped in a section.
http://www.ladislavmrnka.com/2011/03/the-bug-in-storegeneratedpattern-fixed-in-vs-2010-sp1/
When looking at fixes, did not understand that BOTH SSDL and CSDL parts stored in same text.
So look in upper part that it has StoredGenereated Pattern.

Resources