Entity Framework with IBM DB2 - c#

We have a DB2 database which we are accessing via EF. We are able to connect to the database and do read & write operations as part of this.
Now the plan is to initialize the DB using
Database.SetInitializer(new CreateDatabaseIfNotExists<CustomContext>())
This throws out an error saying
HResult=-2146232032
Message=CreateDatabase is not supported by the provider.
Source=EntityFramework InnerException:
System.Data.Entity.Core.ProviderIncompatibleException
Previously we were connecting with
Database.SetInitializer(new NullDatabaseInitializer<CustomContext>());
and this was working fine.
The question is has any one tried creating a new DB2 database from within EF?

You cannot do that.That is Known limitation of the provider.
General limitations:
Only database-first scenarios are supported: any database object that
you reference in Entity Framework must first exist in the database.
Invocation of store-specific functions is not supported.
Trusted context connection properties that you set in the Server Explorer Add
Connection dialog are not passed to Entity Framework connections.
You can read it here : Limitations to Microsoft Entity Framework support

Migration is not supported by IBM EF provider implementation.
If you need DB2 migration support you can use this package that implements only migration (so you can use it in addition to IBM DB2 EF Provider)
https://www.nuget.org/packages/System.Data.DB2.EntityFramework.Migrations/
You can find more info here
https://db2ef6migrations.codeplex.com/

Related

C# switch from local db to external (Azure) db causes errors

I have used the built in Database that comes with Visual studio by using Code First with Entity Framework. Now I wanted to move to an external database so I created one and saved the connections string. So I connected to my azure database by supplying the connection string in the db context constructor. Now though, the problem is that Entity Framework isn't able to create the necessary tables. When I run my application and try to access something, I get System.Data.SqlClient.SqlException: 'Either the parameter #objname is ambiguous or the claimed #objtype (COLUMN) is wrong.'
And I assume this is beacuse my azure db is empty. Why doesn't Entity Framework create the tables?
The error was that I had forgotten to run migration on the new database:
*Add-Migration newDb
*Update-Database

Manipulating RSSBus for Quickbooks ADO.net ConnectionString

I've written an app using the RSSBus QB ADO.net provider - VS 2010 and .net 4.0. I'm connecting to QB with the entityframework 6 and using linq.
I'm dynamically changing the connectionstring in order to manipulate the offline cache. Everything works great.
I've migrated the app to VS 2013 with .net 4.5. In vs2010/4.0 the QB entity object is of ObjectContext and in vs2013/4.5 the QB entity is of DbContext and I don't have the connectionstring property available.
Is there any other methodology to manipulate the cache settings on the connection?
DbContext does not directly have a Connection property but it does have Database which does contain a Connection object which should allow you to edit the connection string:
https://msdn.microsoft.com/en-us/library/system.data.entity.dbcontext%28v=vs.113%29.aspx
There's another method you can use involving a partial class shown here:
EF 5 Changing Connection String at Runtime

C# Provider (with EF 6) internal expression mismatch with SQL

Using EF 6 on Net4.5
Posted a Gist showing the internal Expression and the resulting SQL created by the provider. Notice that the joins on Occasion (from BrandVisited) and BrandInfo (also from BrandVisited) are missing. Plus the provider has directly connected up BrandVisited to Respondent via RESP_ID. This is not the intended behavior and yields incorrect SQL.
Any ideas to what is happening behind the scenes?
Running local against SQL Compact but the production target database is SQL Server.
Just to make it clear. BrandVisited has foreign keys (in the EF model) to Occassion which in turn has a foreign key to Respondent. There is NO framework relationship between BrandVisited and Respondent. Despite that the provider (both SQL Compact and SQL Server) associate these table on the Respondent unique key (RESP_ID). How is this even possible?

Using Npgsql provider with OLE database connection

So I have the following connection string which is causing me issues. I am attempting to write an application which is capable of being database agnostic (difficult but not impossible) and I have come to testing it on PostgreSQL however I cannot seem to get an OLE connection to work with it. From what I have seen it is entirely possible.
I got everything working using a specific class for PostgreSQL but this used the Npgsql types rather than generic OLE types.
E.g.
private NpgsqlCommand m_postgreSQLDatabaseCommand;
Instead of
private OleDbCommand m_oleDatabaseCommand;
This is not acceptable in my circumstances.
I tried simply changing the connection string to use the Npgsql provider but I am not sure if I am using it correctly. I get the error below:
Connection String:
<add name="ApplicationPostgresDefault"
connectionString="Server=127.0.0.1;Port=5432;
Database=myDatabase;
User Id=myUser;
Password=myPass;
Provider=Npgsql"
/>
Error:
The 'Npgsql' provider is not registered on the local machine.
What can be done to solve this?
If I get the provider in there correctly will I be able to communicate with PostgreSQL as I was with Npgsql objects?
The local machine doesn't have the provider installed.
I would suggest using a native client rather than OleDb anyway:
http://npgsql.projects.postgresql.org/
http://connectionstrings.com/Providers/npgsql
that's your choose
Are you missing a ; after Npgsql ?

Using Massive; in a WPF Application with EF

I want to use Massive ORM(by Rob Conerys) in a WPF Application using Entity Framework.
It sais to add in app.config the providerName = 'System.Data.SqlClient'
but using EF I have System.Data.EntityClient and I get this error : "Unable to find the requested .Net Framework Data Provider. It may not be installed."
Any suggestions ?
You can solve this by creating a second connection string specifically for Massive.

Categories

Resources