I have a local, SQL Server Compact database in an application I am creating. I generated a .dbml file I can use for LINQ-to-SQL purposes using the SqlMetal.exe tool, which worked fine - I now have the table objects for use in my application.
I have a strange issue though. Even after calling SubmitChanges() on my DataContext, the data never commits. But strangely, after adding the rows, these rows do appear in the table object on the datacontext, but not in the table. What shocked me is even after stopping and starting my application, these rows still existed in the DataContext - but after a few minutes they seem to disappear.
Have I configured this correctly? Are there any more steps I need to do after using SqlMetal to allow the LINQ to commit changes?
I am assuming that you linked to the dbml file using the default properties. This means that, each time you start a debug session, the file will be copied into your output directory and changes made to it will only be seen for that session (i.e., "Copy -> Always").
If you want the changes to persist then right click the file -> properties -> Copy Never. By default the IDE assumes that you don't want to modify the original database, only a copy for debugging purposes.
Related
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.
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.
So I have a database filled with values already. It works fine, until I start to query any values I have added into it. It just won't work.
I'm using a project on Visual Studio creating a Web Form, while the database connection, as well as the add, update, and delete methods, are stored in a DLL that I referenced.
The adding works, and so does the updating. I can see it in the database through the server explorer, but I cannot query what I am seeing. I tried querying values I did not add, and it works. When I query the rows I added, it won't work.
Let me know if you need anymore information. I have no idea what's going on.
I've encountered a similar issue and the catch to it was that it was actually using another database. I'd recommend you check with SQL Server Management Studio and make sure you're using the correct database and also have a look in Webconfig.
i'm new to MVC and have to update my model.
I have an SQL Server database already connected to my project, today I add a new column. Now I need to update my MVC code to reflect the change.
Everything online tells me to update the .edmx and .tt files with the Update Model Wizard since they are auto generated, but I cannot find the wizard in VS 2012 so I am at a stand still.
Is this the right way I should be doing this? Any tips would be great...thanks
There are a couple options you can do:
If the database is empty or there isn't a lot of data that you care about, you can drop the database and recreate it.
Manually add the column in the database (after property is in model)
There is something called Code First Migrations. This will allow you to update your database. Here is a tutorial you can look at for this: http://msdn.microsoft.com/en-us/data/jj591621.aspx
Double click the edmx file. This opens the diagram of the database model.
Right click and select "Update Model from Database..."
That will start the wizard you're looking for.
Be aware that not all changes come through automatically.
Most obvious is that columns will not be removed from model just because they're gone from the db. If you're dealing with lots of modifications or deletes rather than additions, it may be best to just drop the model and recreate it (as suggested above by Andrew).
No matter which approach you take, I'd suggest making sure you have all other local source changes committed or shelved before starting because you may need to do an undo check out if EF gets freaked out.
I ended up downloading this update of VS 2012 and repaired. Now I am able to update my model.
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.