I would like to use EF 4.0 against Oracle. The challenge I have is that I have multiple databases (all with nearly identical schemas) for different clients. Is it possible to generate my CRUD layer once, and then point at the correct database at runtime based on user identity (or whatever criteria I need to supply)? I think I can handle the small differences between schemas by using POCO classes or just handling it in the partial classes, but I'm not sure how to handle directing to the correct database. Any Ideas?
The most simple solution is to create several named connection strings in your configuration file and then simply to create different instances of the same ObjectContext with different conection string parameter using a parameterized constructor.
Don't forget to delete the Schema attribute from your .edmx file (using XML Editor, for example).
Related
The database I am using is Oracle 11g Express Edition release 2.
I created 2 schemas in the same instance xe. They all have the same tables names and sequences names and stored procedures and stored functions and views names. But the tables structures and views texts are different ( there is some modifications between them ).
The reason for the creation of these two schemas is because our project has two versions. So the first schema is used for the first version , and the second schema was created for the second version. The mechanism of our web application Spring project is that whenever a connection is made through the web application login page then a corresponding Oracle user is making a connection according to the login entered ; so there is no fixed credential connection , there are Oracle users corresponding to each web application login.
So in order for each user to work with each database objects then I created public synonyms for every objects , and granted permissions to them for each user. But the database objects are owned by the schema I mentioned at the beginning. Now my problem is this : our customer wants the two project versions to be run on a same instance ( same computer server ). So one of the project version cannot run because the public synonyms can only refer to a particular schema owner. So how to make the public synonyms work for each schema ?
In short, you can't. However, you can always use a distinct synonym name to identify the object.
Something similar to below:
create public synonym structures_v1 for schema1.structures;
create public synonym structures_v2 for schema2.structures;
Oracle provides 2 totally different technologies for this situation (which comes to my mind):
Editions (and Edition Based Redefinition)
PDBs
With Editions you can create the same Object once in each Edition - but there are limitations like tables are not editionable.
It's not a feature you just enable, you need to understand the concept and implement it properly.
PDBs enable consolidation of Databases with colliding namespace (such as your described synonyms) within the same CDB and therefore save SGA/memory. Basically they are totally separated - limited interference can be implemented when it's concept of object & data inheritance is understand.
What about creating a 3rd Schema and having Synonym and permission to query 1st and 2nd schema. Anyone tested this concept?
I have an ERP application running with Oracle forms and Oracle database. Now I am planning to migrate this application to a java based enterprise application. will it be a good idea to keep the existing oracle database as back end and developing a web application with certain level of changes/additions in the DB design.
There are two facts to know before answer your questions:
has your database schema some oracle forms special structures or is it in 3rd normal form and simply stores data using keys and enforced referential integrity?
How much stored code contains your database?
Ad 1. Oracle forms don't have specific schema reqiurements. They work best if your schema if based on 3rd normal form. If your schema is like this, use it for new Java application. We have both forms and Java EE applications on same database schemas and is works fine.
Advantage is, if you have keys (primary, unique, foreign) in your schema. Use them when generating Java app.
Probably you will have to add #Version columns for optimistic locking (see https://docs.oracle.com/javaee/6/api/javax/persistence/Version.html). But there is not reason to build new schema for it.
Ad 2. Your will have to overwrite bigger part of database stored code (triggers, procedures, functions) to Java. In most cases this does not have dramatic impact to schema structure, but deal with it.
So - if your database schema is not tailored to some UI client needs AND you want only use a new client, use your schema. If not, create a new one.
I want to ask if I had a proper design. Background:I develop my web application with EF4. The application will be used by three offices. The business processes in the three offices is similar with each other. Each office has the database their own, but most tables, SPROCs in the databases are the same.My thinking:I want to extract the same tables and stored procedure to a single edmx file, and point the connection string to database at runtime basing on the logon user.
I add a method to the constructor
MPREntities(string connectionString, string containerName)
And will pass the connectionString and the container name, when initializing the MPREntities. The containerName is the same - "MPREntities", it does not depend on the databases pointed to. The connectionString will be changed according to the logon user before passing in. I have done some testing and seems it works. But is that a normal approach? any suggestions?
That approach will work, and is a good use case for this.
One of the requirements for an ASP.NET MVC (3) app I'm working on is that it must be able to create and populate all required database tables, etc. if it's configured to use an empty database.
Since it's a standard ASP.NET MVC3 app, it uses the standard authentication tables (aspnet_*), along with a bunch of stored procedures and stuff.
What I'm trying right now is creating the tables through migrations (via MigratorDotNet) one by one as necessary (so far only made the aspnet_Users one), hoping they're not all needed; other stuff I'll need includes certain stored procedures, like CheckSchemaVersion.
How can I create these from inside an ASP.NET MVC app?
I also have a SQL dump of an empty ASP.NET MVC database (so it creates all the tables and stored procedures) to extract the relevant SQL from. As a super last resort, if I can somehow run this from inside my app, that may suffice as a solution.
If it matters, I'm using ActiveRecord (backed by NHibernate) with SQL Server 2008 Express .
This is indeed possible. The code is available in my application, Syzite, which is open-source (check AdminController.createAspNetStoredProcedures()).
The solution was to:
Store the procedures into a text file on the server
Iterate over all the lines
Find every set of CREATE PROCEDURE ... )\n as a procedure generation call
Create a System.Data.Linq.DataContext instance
Call instance.ExecuteCommand with the CREATE PROCEDURE code.
I'm pretty new to EF and use to old school SqlConnection....
Question: I have an existing mvc3/EF database context object that already hits a local sql server 2008 instance. I want to add a new connection string in the web config and have the existing DBContext connect to a remote database to run a stored proc.
How can I do this?
If by existing context you mean the same context instance than it is not possible: one context instance = one connection string.
If you need to connect to two databases you need two context instances and pass connection string to them. Even in such case it can have many restrictions depending on your EF usage. Using the same context type for databases with different schema (different tables) doesn't always work as expected.
When using completely different databases the best way is to have two different context types and instance of each of them. But if you only want to execute stored procedure the simplest way is simply use ADO.NET SqlCommand and SqlConnection directly.
One of the ObjectContext constructors takes a connection string as a parameter. That should help.