'Database' is an ambiguous reference between 'System.Data.Entity.Database' - entity-framework

I have database-first MVC application. The database is postgres with dotconnect data provider. The project works fine without a problem. However when I choose another database in same server, I'm having following error from in InitializeSimpleMembershipAttribute.cs class.
'Database' is an ambiguous reference between 'System.Data.Entity.Database' and 'applicationName.Models.Database'
The only deference I can track is the new database is generated from the program called 'dbwrench'. Can anyone explain me what this error is meaning about?

Related

The model backing the 'XYZ' context has changed since the database was created

I am getting following error
The model backing the 'XYZ' context has changed since the database was created.
How can get to know the Entity / Entities which are casuing issues for logging purposes?
The entity name you are having issue with is 'XYZ' of course, as it it exactly specified in the error you posted.
Although i'm not sure which exception you have to catch, and you should probably not do it, it is clear what you have to do.
Here is some helpful information :
The model backing the <Database> context has changed since the database was created
Also been discused here :
Entity Framework 4.1 The model backing the context has changed since the database was created, immediately after creating DB
Where it is told that catch (PlatformNotSupportedException) may be related. But has i said, this may not be the solution at all.
Finally, the problem may be even deeper, if it's the case, look at this :
The model backing the '--Context' context has changed since the database was created - but db is new production database

Entity Framework not returns data

I'm using EntityFramework 6.1.3. I have generated models from an existing database. Now, when trying to query the database, datacontext returns null. The database appears to be empty.
But the database is not empty as I can connect and query it using LINQPad. When googling the problem I came across a similar situation. In that case the EF generated an empty database on the local server and the solution was to tweak the connection string, although without clear details what exactly should be changed.
However, I'm not sure if that is the case in my situation.
My connection string is pointing to the remote server.
It is not possible that the database was created on the remote server, as we don't have authorisation.
The database was not created on my local machine as I dont even have local sql server installed. And my AppData folder is empty.
Any suggestions?
Generated connection string below
<add name="MAST_DEV" connectionString="metadata=res://*/Models.Mast_DevModel.csdl|res://*/Models.Mast_DevModel.ssdl|res://*/Models.Mast_DevModel.msl;provider=System.Data.SqlClient;provider connection string="data source=xxxxxx;initial catalog=MASTER_DEV;user id=xxxxx;password=xxxxxx;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
I don't really know what I was doing wrong. I have created simple project from scratch , generated models again and it does work fine now. Possibly, previously I selected 'Code first from the database' from Entity Data Model Wizard. Whereas this time 'EF Designer from the database'. Anyway, thanks for trying to help. It was my mistake
This is the exact solution for my problem (the answer is copied from here Entity Framework cant use the DbContext, model being created)
"I see you are using the EDMX with Templates (.tt) for generating the classes. But if you are getting the information from a existing database, the wizard will create a ConnectionString compatible with ObjectContext (metadata informations and provider of entityframework).
The problem is that the connectionstring you are using is for ObjectContext (Database First and Model First). For the DbContext you should use the connectionstring without the metadata informations"

MVC WCF Exception metadata was not handled by user code

I am programming both MVC Web application and WCF application to connect them together and both of them work perfectly,however after connecting them I get an exception in mvc application and the exception Exactly:
"System.Data.Entity.Core.MetadataException" occurred in EntityFramework.dll, but was this not processed in the user code.
Additonal information the main webapplication rule is to add and manage user with asp.net Entity using two data base connection the locaƶ database and the Remote datavase.
the Wcf application connected to the remote database and it is role to transmit information from the webapplication to the remote database.
the webapplication without the connection with the WCF work Perfectly but after I add the Reference to my WCF it stop working with this exception.
inner error:
The scheme is not valid. Error:
The assignment of the CLR type to EDM type is ambiguous because multiple CLR types match the EDM type 'tab_OnlineUserClaim'. Previously found CLR type
'ELVIRA_Userverwaltung.ServiceReference1.tab_OnlineUserClaim', newly found CLR type 'Userverwaltung.Models.tab_OnlineUserClaim'. The assignment of the CLR type to EDM type is ambiguous because multiple CLR types match the EDM type 'tab_OnlineUserLogin'. Previously found CLR type 'ELVIRA_Userverwaltung.ServiceReference1.tab_OnlineUserLogin', newly found CLR type 'Userverwaltung.Models.tab_OnlineUserLogin'.
This means that the application is unable to load the EDMX.
You might have changed the MetadataArtifactProcessing property of the
model to Copy to Output Directory.
The connection string could be wrong. I know you say you haven't changed it, but if you have changed other things (say, the name of an
assembly), it could still be wrong.
You might be using a post-compile task to embed the EDMX in the assembly, which is no longer working for some reason.
In short, there is not really enough detail in your question to give an accurate answer, but hopefully these ideas should get you on the right track.

Accessing DB2-LUW 10 with entity framework 6

I am developing an application in which the database is selected by the end user at runtime. The database can either be on a MS SQL server or an IBM DB2 server. I am currently using IBM DB2 10 Express-c on a windows server for testing. I am developing using Visual Studio 2013 C# and Entity Framework 6. I have installed the EntityFramework.IBM.DB2 Nuget package for the DB2 support. I am using reverse-engineer code-first against an existing SQL server database to generate my base code. The application works fine against a SQL Server database.
I am using System.Data.Common.DbProviderFactories.GetFactory to generate the provider.
System.Data.EntityClient.EntityConnectionStringBuilder connectString = new System.Data.EntityClient.EntityConnectionStringBuilder(a_Connection);
System.Data.Common.DbConnection conn = System.Data.Common.DbProviderFactories.GetFactory(connectString.Provider).CreateConnection();
conn.ConnectionString = connectString.ProviderConnectionString;
LB500Database = new LB402_TestContext(conn, true);
a_Connection is provider=IBM.Data.DB2;provider connection string="Database=LISTBILL;User ID=xxxx;Password=yyyy;Server=db210:50000"
and is being parsed correctly by the EntityConnectionStringBuilder.
I then try to access a table in the database with
LBData500.LB_System oneSystem;
System.Linq.IQueryable<LB_System> allSystem = LB500Database.LB_System.Where(g => g.DatabaseVersion == databaseVersion && g.CompanyID == companyID);
I get an invalid operation exception "Sequence contains no matching element" which means that no elements are returned. If I remove the Where so that all rows are returned (there is one in the table) and try to enumerate the result set using the VS debugger I see the message:
"The context cannot be used while the model is being created. This exception may be thrown if the context is used inside the OnModelCreating method or if the same context instance is accessed by multiple threads concurrently. Note that instance members of DbContext and related classes are not guaranteed to be thread safe."
I am not using multi-threading. I am not inside the OnModelCreating.
Just changing the connect string to point to SQL server works fine, so I think my basic approach is sound. If I were getting some kind of error back from the server I would have something to go on. I can run the query from inside Visual Studio, so I have connectivity.
Any pointers would be appreciated.
UPDATE:
I turns out the EF objects were generated using EF5 and the EF6 runtime was being used. I regenerated the EF objects using EF6 reverse engineer code first. I can now connect to the database and get an error message:
"ERROR [42704] [IBM][DB2/NT64] SQL0204N \"DBO.LB_SYSTEM\" is an undefined name."
The schema in the DB2 database is the same as my userid (in this case, not always). I added the CurrentSchema=xxxx to the provide connection string, but EF is still passing dbo as the schema name.
Now I need a way to change the schema name at run time. I saw a link to codeplex EFModelAdapter (http://efmodeladapter.codeplex.com). So I may give that a try.
Update2 After looking through EFModelAdapter, I decided to take a different route. Since I only need database access and not schema management, I decided to go with Dapper (https://github.com/StackExchange/dapper-dot-net). This works great for what I need and allows me to change the schema name when accessing DB2 databases.
As per my Update 2, Entity Framework was a little overkill for what I needed. I switched to dapper https://github.com/StackExchange/dapper-dot-net and I am working fine against multiple DBMSs.

DropCreateDatabaseIfModelChanges not dropping the database

The DropCreateDatabaseIfModelChanges initialisation strategy no longer works in MVC5 with ASP.NET identity.
I'm getting the following error:
The model backing the 'BaseModelContext' context has changed since the database was created. Consider using Code First Migrations to update the database.
What do I do if for now I don't want to use migrations? Shouldn't the fact that I've TOLD it to drop the database that it should then go and do it?