My entity data model wizard is not showing new tables - c#

I've created a database from scripts using Microsoft SQL Server 2019 and generated some classes in C# using Entity Framework. Now I've had to modify and add a number of new items to that database, including stored procedures and new tables.
However, on trying to regenerate the classes in Visual Studio 2019, the Entity Data Model Wizard is still showing the old database (the way it looked a week ago), including some tables I deleted. None of the new stuff is listed. I've tried deleting and recreating the database, restarting both programs, and restarting the PC to no effect.
The steps I'm taking to generate the framework in Visual Studio are:
Add a new item to the project.
Select ADO.NET Entity Data Model.
Select Code First from database.
Select Next (the connection string is already filled in).
The next screen is the "Choose Objects and Settings" window, which is where I'm still seeing the old tables (and not the new ones).
Is there some special step I need to take after changing a database to get those changes to show up in Entity Framework?

Related

SQL table getting deleted by itself in local db, using LINQ to SQL [duplicate]

I'm making a WinForms app in C#. When I go to create my database object, I'm presented with two options:
Local Database
Service-based Database
All I want is a simple local database to use for my project.
However, if I select "Local Database (Compact Edition)" then after I create my tables and drag them over to a LINQ-To-SQL Class creator it says:
The selected object(s) use an unsupported data provider.
So, I don't know why creating a local database would be considered an unsupported provider when dragging to tables to the Object Relational designer.
So, I try the second type, "Service-based Database". I lay out my tables how I want for my basic application and make my tables. The LINQ-To-SQL Designer works fine when I drag these tables and I proceed to write my code in my app to insert and upate the database entries.
However, with this second "Service-based Database" my inserts and updates work as long as the application is running. However, once I close it it reverts back to what it was before. If I manually add in data via the Server Explorer it persists but any inserts I do don't save.
Why can't I create and use a Local Database with LINQ?
If that isn't an option, then why isn't the "Service-Based Database" (whatever that is), persisting beyond the application closing?
Thanks for your time!
Edit: Apparently the LINQ-To-SQL Object Designer doesn't work on Compact Edition Local Databases. It can still be done, but you have to use SqlMetal apparently to generate the dmbl file.
When you compile, the old database gets erased and a new one is copied to the bin folder. Therefore try link (using linq) to the database in the bin folder. Try change your connectionString.

C# Edmx - update a database

I have a question. I have a project that uses an edmx and all hooks up fine to the sql server.
I have installed it in several servers.
What I want to know is, having made changes in development so m database and my edmx are change,s say a new table and a modified one.
How do I make it so these updates are aplied automatically when I publish an app update?
I remember once a long time ago doing code first database work and making some kind of file or procedure that would automatically apply these changes when the app ran.
Can any one fill me in again.
1.- AFAIK, when you're using model first or database first, you can't use Migrations, you generate a DDL script that when executed, creates the database or drops and recreates tables losing any data you had.
See This link read point number 5.
"The script that is generated will drop all existing tables and then recreate the schema from scratch. This may work for local development but is not a viable for pushing changes to a database that has already been deployed. If you need to publish changes to a database that has already been deployed, you will need to edit the script or use a schema compare tool to calculate a migration script."
What I do here, is make the changes to the database and update the model (Right click edmx designer, click "update model from database")
2.- You can configure updates on a ClickOnce installer, any changes made to the edmx will be published on your app.

Database changes not propagating to entity model

I'm using EF5 with C# and SQL Server 2012. We're using database first. I made some changes to the database, added a couple views and a few table columns.
When I go into the edmx file in Visual Studio 2012 and select Update Model From Database everything is shown in the model view. The new views are present as well as the new fields.
But none of the new elements propagate into the auto generated model.cs file. I've updated the model from the database multiple times and rebuilt the solution many times as well.
Is this a bug? Is there a workaround?
Right-Click on the tt-files (one for the dbcontext, and one for the containers) that is connected to your edmx-file. Click "run custom tool". This will rebuild your containers

Databases in winforms c#

I can't understand how to manage database with Entity Framework.
I'll try to describe my problem step-by-step
create winforms application
add database (.mdf) to solution
when appears window "choosing database model", select dataset
then finish, as database is empty
go to server explorer, choose created database, create some tables
add to solution EDM ADO.NET
The problem is that new data doesn't appear in my database in server explorer. This means that while my Winforms app is working, I can modify my database (change existing values, add new, ..). but if I close my app, there is no update in my database in server explorer. I DON'T forget to use function SaveChanges()
P.S. while my app is working, values are updating. Think, that means that data updates in dataset, but not in database. if i am right, give a clue how to update database from dataset.
pps. visual studio 2010 ultimate. sorry for english
dbentity db=new dbentity();
db.items.addobject(new item() {value=something});
db.savechanges();
Don't add the database to your solution. You can use the Server Explorer to add a connection to your database via your existing SQL Server, or you can select your database in the wizard that appears when adding a new EDMX file to your solution.
Did you try either of these? Where did you get stuck?

LINQ Confusion - Database not persisting after the application closes?

I'm making a WinForms app in C#. When I go to create my database object, I'm presented with two options:
Local Database
Service-based Database
All I want is a simple local database to use for my project.
However, if I select "Local Database (Compact Edition)" then after I create my tables and drag them over to a LINQ-To-SQL Class creator it says:
The selected object(s) use an unsupported data provider.
So, I don't know why creating a local database would be considered an unsupported provider when dragging to tables to the Object Relational designer.
So, I try the second type, "Service-based Database". I lay out my tables how I want for my basic application and make my tables. The LINQ-To-SQL Designer works fine when I drag these tables and I proceed to write my code in my app to insert and upate the database entries.
However, with this second "Service-based Database" my inserts and updates work as long as the application is running. However, once I close it it reverts back to what it was before. If I manually add in data via the Server Explorer it persists but any inserts I do don't save.
Why can't I create and use a Local Database with LINQ?
If that isn't an option, then why isn't the "Service-Based Database" (whatever that is), persisting beyond the application closing?
Thanks for your time!
Edit: Apparently the LINQ-To-SQL Object Designer doesn't work on Compact Edition Local Databases. It can still be done, but you have to use SqlMetal apparently to generate the dmbl file.
When you compile, the old database gets erased and a new one is copied to the bin folder. Therefore try link (using linq) to the database in the bin folder. Try change your connectionString.

Categories

Resources