Entity Framework with Oracle AND SQL (switch automatically) - c#

I maintain an asp.net MVC application which uses Entity Framework (database first) and connects to an oracle database.
My question:
How can I switch between oracle and SQL server using entity framework?
The meaning has the ability to get data from both oracle and SQL server. Also, the switch from oracle to SQL server (if it is possible) should be automated.
After a search, I found that I can switch between oracle and SQL server in the same app by:
Creating repositories for 2 models
Using mapping with 2 .edmx files. In this way, one of them will generate the code of model and entity classes and the other is used as a source of XML resources.
Also, I found other useful info but they are all very general.
How do I convert oracle edmx to the sql_server equivalent?
During my search, I migrated my oracle database using Microsoft's SSMA to an SQL server database so now I have the same database in oracle and also in SQL SERVER.
Does someone knows the steps to get me a bit closer to solution?

Related

How can I Reverse Engineer Default Column Values that use scalar functions with EF Core?

I'm looking at upgrading our Storage Layer form Linq To Sql to EF Core 3.
I can reverse engineer the model from the database using the scaffolding command and it correctly creates FK fields who's default value is looked up using a Scalar Function called dbo.DefaultSystem()
But then I can't use EF Core to create a database from scratch because it can't scaffold programmability.
Is there, like, some kind of pre-create hook I can grab? Or better yet, a way to trigger code after the Systems table has been created.
Once Systems has been created I can just execute some SQL to create the DefaultSystem function.
I have to assume that there's logic in EF Core that knows it has to create the Systems table before it creates all the tables who have foreign keys pointing at it?
Update for comment from JDWeng
"You [create? - ed] the database first. What is your connection string? Are you connecting to a server (the server attached to an MDF file) or a LocalDb which is an MDF file?"
Source Connection String for Reverse Engineering:
#"Server=SQLDEV01\2008R2;Database=Database_Version_88;Trusted_Connection=True;"
Destination Connection String to test db.EnsureDeleted();db.EnsureCreated();
#"Server=(localdb)\mssqllocaldb;Database=LocalDevTest_Version_88;Trusted_Connection=True;"
So, the source database is hosted on a Windows Server running Sql Server 2008R2. This is our restricted schema design server which holds the design for our database. We create schema shapshots and upgrade scripts between the multiple database versions. This server is considered design gospel.
The target database is a (localdb)\mssqllocaldb which is created via EnsureCreated() from the DbContext generated by the Scaffold binaries.
I don't know much about the internals of this but according to your comment I'm just creating and connecting directly to an mdf file.
If there's nothing automatic to do this, I guess I'll have to create the database first with the System Of Record tables pre-created and configured and seeded.

.NET report getting data from both MSSQL and Oracle

We are using SQL Server 2016 and Oracle 11g (in the process of upgrading to Oracle 12c) .
I'm not a .NET developer; therefore, examples will be very helpful.
Our developers are trying to combine data from both MSSSQL (in-house applications) and Oracle (ERP systems) to create a report in .NET (so just reading from both databases).
The developers are adamant they need to install Oracle client on the server hosting MSSQL.
From the security perspective (surface area exposure), we are encouraged to minimize surface area exposure as much as possible. And I found a possible way on this blog. And this blog that seems to suggest creating a function as connection string.
Questions:
Is there not an option in .NET (array, etc) to hold data from either MSSQL and / or Oracle in memory for comparison (using employee id) with another database?
Since it's only a read, is it an overkill to have full Oracle client installed on the server?
How are the experts here if you need to pull data from both DBs?
Thank you.
At some point a machine will have to have the Oracle client. I don't know of a way to connect to Oracle without it.
I can think of two ways to do this. You can link Oracle tables directly in SQLServer. I presume you can then use the SQLServer dialect to query the Oracle table. I'm sure there is a performance penalty for this, especially if joining across RDBMSes.
A second option is to have some sort of table on your SQLServer that has a copy of the Oracle data. Depending on how much data there is or whether or not you retain it, it could be faster than querying the linked table with a join. It could be a permanent table or a temp table. You'll still need to query the Oracle machine and this done as needed or on a schedule.
If you have very little data, you may not even need a table.
You could also have another machine that performs the query of the Oracle DB and moves the data to SQLServer. You wouldn't need the Oracle client on your SQLServer, but on that machine.
I'd look into building a windows service running on a different server from MSSQL server that would utilize the managed Oracle client to ETL data from Oracle to MSSQL server on a schedule which would allow your .NET report to access the report data from one location, your MSSQL server.

How to use LINQ for standard C# application with local database file?

I'm used to work with ASP.NET and I have no problems there, but now I need to create a C# Console application and something is wrong.
I create console application
Add new item to project (Local database)
Fill in some basic data (id, name)
But when I create LINQ to SQL Class and drag my table to it like I do in ASP.NET I get error
The selected objects use an unsupported data provider
What am I doing wrong here, how can I make my work with databases using C# Console/Windows application as fast and easy as with ASP.NET applications?
The database driver / provider needs to allow for the usage of linq. If you are using a simple sqlite db, I would recommend using the DBLinq provider.
If you are using Microsoft's lightweight database (Sql Compact) then I believe this article maybe helpful.
The Object Relational Designer (O/R Designer) supports only the .NET Framework Data Provider for SQL Server ( System.Data.SqlClient).
Where as sdf local DB is a Compact Database. SQL Server Compact Edition (System.Data.SqlServerCe) is not supported by O/R Designer.
Instead you can create a db in SQLExpress and connect to Designer

ORACLE Data Provider Not showing up as an Option

I am trying to use ADO.NET Entity DATA model (edmx) to connect to Oracle, i have installed the Oracle data provider from Oracle.
But i do not see the data provider as an option when i try to add a new connection for the ADO entity data model.
However I can see the Oracle data provider when i am trying to connect to the DB using from the sever explorer in VS 2010.
Any ideas ?
i had to install this beta version to get it to work. http://www.oracle.com/technetwork/topics/dotnet/downloads/oracleefbeta-302521.html

Is Nhibernate using ADO.NET for connecting to database?

What is the data provider for nhibernate? Is it ADO.NET?
Yes it uses ADO.NET internally.
Take a look at http://community.jboss.org/wiki/DatabasesSupportedByNHibernate.
It shows what tools/drivers are used to connect to different databases. for example:
Oracle 9i and 10g are supported, both using Microsoft driver (System.Data.OracleClient) and using Oracle driver (Oracle.Data.OracleClient).
Or:
To work with Firebird, install the latest Firebird .NET Data Provider.
I'm not sure whether it uses ADO.Net for SQL Server connections under the hood, But it seems that it doesn't use ADO.Net for other database systems.

Categories