tete
tete

Reputation: 4999

Entity Framework migration from MySQL to SQL Server and the Table names missing "dbo"

I am maintaining an existing (and working) C# project which uses Entity Framewwork 6 to do the ORM. Now I need to migrate the database from MySQL to SQL Server. So far I have been able to make the program compile by modifying the .edmx file (For example, I changed the Provider from MySql.Data.MySqlClient to System.Data.SqlClient and ProviderManifestToken from 5.6 to 2008. Also I needed to change some data types in the ssdl content, for example from double to float).

Now when I run a simple LINQ query against the ObjectContext-derived context like this:

var query = from data in context.user select data;
var users = query.ToArray();                    

It gives me the exception "Invalid object name 'MYDBNAME.user'."

Apparently a ".dbo" is missing, i.e., the translated SQL query should be

select * from MYDBNAME.dbo.user

instead of

select * from MYDBNAME.user

But I am not sure how I can instruct EF to add the ".dbo". Is there some configuration/option to do that?

Upvotes: 1

Views: 1177

Answers (1)

Raheem Khan Dawar
Raheem Khan Dawar

Reputation: 149

It's very simple and easy approach You have to follow the below steps I hope it will work in your case.

  1. You have to build all your schema in MSSQL Server from that MYSQL

  2. Once you have completed your Database Schema in MSSQL Server

  3. Then you have to follow the database first approach in Entity Framework and It will automatically build all you models and DB context from the database.

  4. How to generate DB models and context (Database First Approach) Data Base First EF

  5. Then You will be able to apply Linq on the database and queries. Thanks

Upvotes: 1

Related Questions