Changing schema name on runtime - c#

I use Entity Framework 6 with an Oracle database in my project.
I have a problem: in my .edmx file (open in xml editor) all my triggers and tables has a name(schema) before the real table name or trigger etc, every time I install my project in new environment and database have a different name its try oldSchame.table and returns an error.
So for now I open .edmx in xml editor and delete all schemas name (remove schema.) and it works, but if I update my database schemas name back etc.
I have found many questions about this but all answers are old (e.g. from ~2010, and referring to Entity Framework 4); what is the best way to solve this problem for Entity Framework 6?

Related

Entity Framework remove all references to database for replacement with a new entity data model

I have an inherited project using Entity Framework, database first, where I need to remove all references to an Oracle database and replace with new references to a SQL Server database.
Adding the SQL Server plumbing is easy: "Add->ADO.NET Entity Data Model"... but since the old database and new database have so many (all) similar tables, there is a lot of overlap and I can't easily tell which references are to the old DB and which are to the new DB. No, I don't have the git history to find that commit and revert it, even if by hand.
My new approach is to completely remove all references to the old DB, not just the .edmx file but also every other file that was added to the project when the original Oracle Entity Data Model was added...but there is no "Remove->ADO.NET Entity Data Model".
Is there documentation anywhere of everything I will need to remove? Or to procedure to find all of those references?
I want to end up with code that has everything except the actual mapping to a database, at which point I'll add the new entity data model and, since the tables on the new server are named exactly the same as the old, the existing code will start working again with the new database/server.

System.Data.SQLite.EF6 Entities not found after modifying edmx diagram

I'm using EF6 with System.Data.SQLite 3rd party provider (there is no native support for SQLite in EF6).
I have to add inheritance between two tables. Because I can't do this on database level, I have to modify the .edmx diagram:
remove the original connection between the two tables (1:N connection), and replace it with the inharitance
rename one of the two tables, because EF automatically generates the name, which is not fit to our naming conventions
After I do this Visual Studio won't see the tables (none of them, nor the tables I have not modified), and I get several errors after build ("The type or namespace '' could not be found." ). Also, all of my table.cs files get removed from under ApplicationDatabase.tt.
If I undo the changes (revert back to the 1:N connection), and save the diagram and the database model everything works fine again.
What am I missing during the changes?
Ok, I solved it by removing the Id from the inherited table. I think the problem was that both tables had an Id, and it conflicted somehow because of the inheritance. Now everything just works fine.

Cannot update Entity Framework model after schema name change

I am on a project that has an EF model that was created with a schema of 'dbo'. At some point in time the schema was changed to something more meaningful. However, try as I may I cannot now update from the database with the newly named schema as all the entities create new objects instead of updating the current ones. For example instead of Person, I now get and Person1. I have tried to edit connection strings as well as the EDMX file but nothing seems to be working.
Is there anyway to get my model to update from the database with the renamed schema?
I am using EF 6.0 and .Net 4.5.

Same table names, different schema issue in EDMX (Database first)

I have two tables with Same table name and different schema in the same database.
For example - Vendor.Employee and Customer.Employee
I am now adding EDMX file in my Class Library project under VS 2012. I am using EntityFramework 5.0.
Though it creates edmx files successfully without any issues, but it creates these entities with different names (like, Vendor.Employee is created as Employee entity, whereas Customer.Employee is created as Employee1 entity.
I understand its because both the classes are directly under same namespace, and so they get created with same names.
But is there any way (for example, giving namespaces per schema) or alternate to resolve this issue so we can have same table names.
Any help on this much appreciated.
Thanks and Regards

how to use MySQL and MSSQL both in ASp.net application with Entity framework

I've written a ASp.net C# .NET 4.0 application and I've used Ms SQL2008 DB.
It's a 2 tier application... BLL/DAL and UI
I have used
- tables (with multiple index to make the record unique)
- relationals between tables (1 to m relation)
- Entity Framework for Datamodel
- LINQ (update/insert/select/delete)
I haven't used
- Storedprocedures
- Views
- Tsql
- no manual SQL operation
- etc.
So If you see it's very easy setup. The application uses MsSQL2008 DB
so my question is: I need to use MySQL (request of client).
What do I need to do? Since I've used Entitiy Framework I think this should be easy done right?
How can I make that the application can use MySQL / or can support both (my SQL/Mysql).
please advice?
EDMX file consist of three parts:
SSDL - description of the database. This part includes information about used database server
CSDL - description of your classes
MSL - description of mapping between SSDL and CSDL artifacts
If you want to use multiple database servers you must have at least separate SSDL for each of them (if you are going to use different table or column names per database you must also have separate MSL).
When your library is compiled those three parts are extracted into separate files and included as resources to your compiled dll. That are those strange things referenced from EF connection string. You can switch the generation in EF designer and those files will be deployed to your bin directory instead.
The problem with supporting multiple database server is that you need multiple SSDL files. VS and EF designer allows you working with SSDL only within EDMX and each EDMX can have only single SSDL. So your options for supporting multiple DBs are:
Separate EDMX for each server. That makes really big problems because you must synchronize them and you must ensure that CSDL part will be exactly the same.
One CSDL, one MSL, two SSDLs in your project. Again this is really problematic because it means having single main EDMX and separate SSDL (it is XML file) where you will maintain all DB description again.
Only one EDMX for MSSQL server with artifacts deployed to bin directory + separate postprocessing which will take SSDL and creates second one for MySQL automatically. This is imho best option. You need to detect differences in used types between MySQL and MSSQL (you can use trick described by #ChristiaanV to find those differences but make sure you backup your EDMX because you will have to revert it) and write either custom console application, script or XSLT transformation which will convert SSDL for MsSQL to SSDL for MySQL. You will end with one CSDL, one MSL and two SSDLs where the second is autogenerated from the first one.
To make it work at runtime you need MySQL provider for EF - for example the connector mentioned by #ChristaanV and you must reference correct SSDL in connection string for MSSQL and MySQL.
Btw. next time learn which DB customer requires before you develop the application. It is real analysis / requirement failure to develop application for platform customer don't support.
You can install the Mysql .Net connector and in your EDMX file you can select DDL Generation Template = SSDLToMySQL.tt (VS)
It will than generate the sql code based on Mysql.

Categories

Resources