Switching from SQL Server CE to SQL Server Express entity issue - c#

My application uses SQL Server Ce for the database and Entity Framework as the ORM.
Now I'm trying to switch to SQL Server Express but I'm having trouble doing so.
UPDATE
So after banging my head for 3 hours I finally figured out that you cannot use an Entity model generated from a SQL Server CE database against a SQL Server (in my case Express version).
I used a Diff program to view the generated files (Designer.cs) for both databases and I noticed these differences in the file:
SQL Server CE SQL Server
FK__Download__000000000000003F FK__Download__PlaneI__0519C6AF
So I have to create two entity models, but how can I interchange between the two in my program?
If I create two entity models, I'll have two classes with the same object names.
Thanks in advance

The EDMX file actually consists out of three parts.
CSDL, your conceptual model
SSDL, the storage model
MSL, the mapping between those two.
Normally these three parts are embedded in as a resource in your assembly and the connection string that you use tells the runtime to look for them in that assembly.
You can however use physical files and deploy them with your application. In such a way you can use the same CSDL but a different set of SSDL/MSL for the specific database. In that way you can reuse your entity model against both your SqlCE database and a SQL Server database.
Here you can find a blog post about swapping EF metadata

Related

How to generate schema diagram from POCOs

I'm learning EF Core with SQL Server and trying to generate schema diagram among POCOs. I implemented the code-first approach and want to get a schema diagram shows each entity and relations.
I tried to generate the schema from Database Management Studio, but it doesn't contain navigation properties information. So, how to do that?
You can achieve that usually by creating a physical database using dotnet ef database update or other migration method and then using your db provider to reverse engineer the schema for you. For example, if you use SQL server, there is an option to create database schema in the SQL Management Studio UI. Other DBMS will likely have similar options.

Oracle and SQL Server database with same schema in single Entity Framework

I have a task in my existing application that we have 2 different databases, one in SQL Server and another in Oracle, but both schemas are the same.
Currently we have an ASP.NET MVC application using Entity Framework and SQL Server. Can I use the same entity model against the Oracle database, without code change? Because some of the datatypes in Oracle and SQL Server are quite different, so common entity model .edmx is not working and code also throws error. Is there any way to achieve this?
Please give me a hint so I can go further.
I found out that one solution is to use the same csdl amd msl part of the edmx file that you have already created through your sql server connection and have different ssdl for every database type.
If you don't know where they are located in your project or how to access them just right click in the edmx file in you solution explorer and select open with and choose xml editor.
there you can see that each part has it's name in comment's section
Moreover there is a Microsoft tool EdmGen.exe that is part of .net framework(so do not have to download it ,you have it already)
Info about the tool:
https://msdn.microsoft.com/en-us/library/bb896270(v=vs.110).aspx
Through this tool you can convert the ssdl file to an oracle equivalent .
Due to the fact that is something i am working too these period i dont have a full answer but that can give you a start

What changes are needed to switch database from SQL Server to Oracle using Entity Framework?

I have developed a MVC web application using Entity Framework with SQL Server as backend. I have used a database-first approach.
Now my client wants to switch to an Oracle database. I am in the process of doing impact analysis of switching from SQL Server to Oracle database. My client believes that it is as simple as changing connection string.
My question is, considering the fact that the table name, table structure, relationships and attributes are all same with SQL Server database, what changes do I need to do in my project to switch from MS SQL to Oracle?
Do I need to create a new edmx file for Oracle database or do I only need to change the connection string and use the same context?
Also if in future this needs to be reversed, then is there a good practice or solution to support both the databases?
Thank you.
oracle has a 30 character limit for item (table, index, column) so if you are verbose in any of your naming you are going to have to rename a bunch of items.
i don't like using an edmx. it might be easier with code first models.

How to use Linq-to-SQL with Oracle database

I am trying to using Linq-to-SQL with an Oracle database. I had using .dbml file but its giving exception for Network Instance due to not available SQL Provider. So please guide me how can I use Linq-to-SQL with Oracle database.
Linq-to-SQL is a SQL Server only solution - it was designed by the C# team (not the database folks) only as a "proof-of-concept" for the LINQ capabilities.
If you need support for other databases - like Oracle - you need to use Entity Framework instead (which was created and still is being further developed by the ADO.NET/database team at Microsoft)

Deploying my application that uses Entity Framework and creating databases on the client machine

I created the model in Entity Framework, and then created the database from that model.
What would be the best way of doing this in the client machine?
If Entity Framework try to connect to the database and find the necessary tables and those do not exist, it will give an error.
What is the best way of create those tables in the client machine?
Using the SQL file generated by the model? If so, how can I execute it?
In case that matters, I'm using SQL Server Express, although this question could be kind of generic for any database.
You can copy that script and use it in the client as well... I don't understand the problem of doing that.
This article has information on how to generate SQL script to generate DB.
http://www.dotnetcurry.com/ShowArticle.aspx?ID=606
It say to right-click the entity-designer, and then "Generate Database from Model...", after that you enter the information of the DB connection, click next and you have the SQL.
EDIT:
Information on how to read and execute an SQL file:
I found this one in microsoft forum:
http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/43e8bc3a-1132-453b-b950-09427e970f31/
This question here in SO:
How to execute an .SQL script file using c#
There is no native .Net way of doing that in a DB agnostic way I think.

Categories