Is it possible to update a sql database schema from an edmx in Visual Studio 2008? - linq

So with LINQ-to-SQL I know you can update the database from the LINQ objects and update the LINQ objects from the SQL.
I am using LINQ's entity framework (a.k.a. LINQ-to-entities) and I can update the entities from the SQL database, but I can't update the database schema by changing the entities.
This is frustrating. Is there something I am missing? Am I doing something wrong? If this is not possible with Visual Studio 2008 is there a plug-in or other 3rd party application that will do this?

Right now the EF model can only be generated from the database. The database cannot be generated from the model.
Something that is talked about for future versions.

I have been working on extending the LINQ to SQL Database Sync(*) (csdb.exe) tool to work with edmx files. For now, I have got a preliminary, but working, version that can generate and update tables in your database. Relations are not working yet, and you will probably run into some other issues. The code is available on github, under the Ms-PL (as was the original csdb.exe).
Please note the database connection string and edmx filename are hardcoded for now. This is my prototyping version, not a release one ;)
(*) Please google the original tool. Stack Overflow does not allow me to post more than one link...

Related

Is it possible to see the data model diagram in vstudio when I use EF Code First?

Once I create my data model using Code First, I would like to see it diagrammed, is it possible? For example, when I use Database First, I generate an edmx. Is there something similar for Code First? Thank you
How about creating a new project for the same database , that uses model first? Just use the project to display the model, not update it.
If you are using SQL Server you can use the Database Diagrams from within Management Studio. Unfortunately I can't see the diagrams in the SQL Server Object Explorer in Visual Studio.

Database update from Oracle 9g to Oracle 11i. What are the appropriate .dll’s for .net MVC 4.5 web application using Nhibernate?

Oracle Database is being updated where I work, and I need to know how this will affect .net Application that uses Nhibernation for Mapping to the database.
I basically need to know what appropriate Nhibernate dll files for update from Oracle 9g to Oracle 11i.
What changes would have to be made on the Web.config file?
What dll files are needed in the output directory?
The only online Document I found online was; http://nhibernate.info/doc/tutorials/first-nh-app/your-first-nhibernate-based-application.html
However this online example uses a Microsoft SQL Database.
unless you are going to start using the new features of 11g, then I'm pretty sure nothing needs to change.

ODAC/Entity Framework Model Update Issues

We are looking to introduce odac into our application but I am running into a number of issues and I can't seem to find any solutions that fix our issues.
We are using an oracle database and trying to use ODAC 12c Release 1 (12.1.0.1.0) with Oracle Developer Tools for Visual Studio.
In our model we would like to have multiple schemas so we can perform cross schema queries. The schemas which we select in the filter for the database connection appear when we are creating the model. However when we try to update our model from the database only the default schema is visible. Sometimes this can be fixed by opening the relevant part of the database in Server Explorer in Visual Studio but this doesn't always work. This fix never works after we add multiple connection strings for the same model (depending on the location of the user will depend on which database the user gets directed to).
The next issue we are having is that we can't the return types of stored procedures to be auto-generate. I have tried to retrieve the column information but it is never able to retrieve the metadata. I have seen a few suggestions of modifying the stored procedures then getting the column information and reverting the stored procedures but this is something we would like to avoid. Also the suggestions don't seem to work on oracle databases (but that could be me, I don't have much experience with databases).
The final issue (this is a minor issue) is that I cannot figure out how to get the generate code to omit underscores from the classes/methods generated. This isn't a huge issue it is purely to make it easier migrating the code we have.

Save/Automate LINQ to SQL Adjustments in Editor

I'm generating domain model using LINQ to SQL via the VS2008 built-in editor. That works really well, too; when I adjust my database schema I simply delete everything from the editor and then pull it back in from the server explorer by selecting all tables and dragging them into the designer surface. That works great too.
Now the problem: I have properties that I manually set to autogenerated, readonly etc. using the property inspector on the right. Everything I re-create the entire schema I have to do this manually all over again.
Is there a way to persist these settings externally and/or automate them to bring it back to the state from before?
You can use something like the Huagati DBML Tools. This will allow you to update the DBML file from the VS designer.
I've also used the following process before:
Create my schema in SSMS
Create a script that uses the SQL Metal command line tool to generate the DBML file
As the DBML file is XML, you can run transformations on the file. I used this to simply change a few things like setting certain fields to be auto-generated (DateCreated, etc).
Then, either use SQL Metal or T4 to create the model files from the altered DBML file.
This process worked great - however I had complete control over the database schema. This process also allowed me to use L2S with SQL Server Compact Edition.
Hope this helps!
T4 Toolbox has a Linq to Sql Schema generator which allows you to develop your Linq to Sql applications in a model first approach. I have used it a little and it works really well, here is a blog post with details and usage info.
Your solution may appear to work when you have very few database entities / tables, but it does not scale and as you've found, syncing is less than ideal.
Do not use the Visual Studio 2008 LinqToSql O/R Designer
After looking at many alternatives to the problems you are describing with LinqToSql, I decided to abandon LinqToSql altogether as I didn't find any of the workarounds very good. Competing ORMs don't have the silly problems that LinqToSql has and they are much more mature and feature rich.
I could/should probably list some of the alternatives I ran across, but I don't want to spend the time and give you false hope, sorry.

LINQ to SQL - How to deal with changes to database

I'm fairly new to LINQ to SQL, so I could be missing something basic here.
I created a LINQ to SQL layer, generated all the dbml files etc., and created a LINQ query which worked fine. I then made a change to the database, and wanted to get that change reflected in the ORM layer. To do this, I deleted my ORM layer and created a new one (may not be the best way?).
Now my code is not able to see the datacontext object in intellisense and won't compile. I imagine this may be something simple, but I'd also like to understand the bigger picture of how to update the LINQ to SQL ORM layer when the database changes.
Yeah, you don't want to delete your whole DBML file. Open it in the designer, and delete the table that changed. Then drag'n'drop it again from the "Server Explorer" (in the view menu). This will load an updated copy of teh database...
Note that if server explorer is already open while you make the change to the SQL schema, you'll need to refresh server explorer so it has the latest versions.
The drawback to this approach is that if you do customizations to the table in the DBML, those need to be redone. This is an infrequent case for me.
I remember having this issue a bunch. The fix is simple, really. Rebuild your solution! The DataContext and other such classes are generated during a build.
Quite a headache - I wish the DBML tool did this for you when you closed it.
You can also use SQLMetal to update your DBML classes. Some people even write a script or batch file to automate the process.

Resources