I have a SQL Server database and Entity Framework Model setup with POCO objects, this is working fine. However, I have also created a Sqlite database from the SQL Server database (using a simple conversion process).
So I have created another EDMX file for the SQLite database, which I would like to use my existing POCOs generated from the SQL Server model and map them to the database. Unfortunately this maps the SQLite primary key integer columns as int64 (this seems to be the underlying integer type in SQLite), when they are simply ints in the SQL Server database.
This means when I try to map the new SQLite EDMX to my existing POCO objects (generated from the SQL Server EDMX by the POCO T4 Template), the objects cannot be mapped at runtime (and throw exceptions) because the id columns differ in type.
Does anyone know of a fix for this, for example is there a way to convert values in the entity framework edmx file? If there isn't I would consider this a fairly major limitation of the entity framework.
Thanks for any assistance.
Related
I am using EF core and SQL database in my project. I have data model with several entities (principal with child/dependent ones) and as key I used int IDs. My entities have also defined unique UUID property for other usage. One of the is to identify same entity in test/production environment because primary key is not consistent. That means entity on test server ID=1 is not the same entity on other SQL server with production environment.
I thought using INT ID would be a good performance choice BUT I came to a problem:
I am in need to transfer selected data (entities) from test to production SQL server. My idea was to serialize those entities to JSON via .NET core native serializer from test machine and loading them to production one.
I am able to identify individual entities between enviroments via UUID property, but the problem is with setting relations/navigation between them. Have anyone solved similar issues?
I have an application which is using Entity Framework 6 in order to interact with a SQL Server database. I have several migrations files due to the evolution of the application.
Now, I'd like to add the possibility to choice between a SQL Server database and a PostgreSQL database with keeping the same entity model.
When I apply the migrations files on SQL Server, all is ok.
But when I apply the same migrations files on PostgreSQL, it says that the database does not match the entity model and I have to generate a new migration file.
If I generate a new migration file, I see that it want to remove the property unicode on all string columns. I think it's because on PostgreSQL the type varchar (character varying) is able to store unicode and non unicode characters.
If I apply this migration file on PostgreSQL, all is ok now. But if I apply it on SQL Server, it say that the database does not match the entity model => columns varchar has been replaced per nvarchar.
I thought that the migrations files was able to adapt to the provider but apparently not.
For information, the property unicode is manage like that in the onModelCreating method :
modelBuilder.Entity<MyTable>()
.Property(e => e.ColumnName)
.IsUnicode(false);
So, my question is, do I have to manage different migration files depending on provider, knowing that I want to keep the same entity model ? If yes, how can I do this ?
Thanks a lot for your help
I have found a solution, I'm not sure it's the best but it's working.
In order not to be annoy anymore, I've created a batch migrations files per provider.
For that I've created one configuration per provider with specifying a specific context key and a different folder containing the migrations files.
This permits to switch between the different configurations depending of the current provider.
I have a project which uses entity framework.
We map a mssql db with entity framework. Now we want to change mssql db to oracle db. But I don't want to change my model of db in entity framework. Two dbs are same tables columns etc.
only difference is their technologies(mssql and oracle) and some of the column data types.In mssql we use bigint instead of number in oracle. Is it possible to use same model with difference dbs which have same tables on Entity framework?
The provider model with EF allows support for a variety of databases. I believe this includes oracle however I haven't ever used it personally.
I can tell you that when switching between database providers the connection string is normally the only change required. The only time i think you would have to change anything at all in your database is if the provider didn't support a specific operation you are using.
I am working on a asp.net mvc project and using Linq for all my data related operations. In such cases, do I need to define relationship in the SQL Server database ??
I am using Entity framework and Linq so I think it doesn't matter if I create an E-R diagram(i.e defining relationship) or not.
By 'define relationship' I assume you mean 'Foreign key constraints'. It is always advisable to define constraints in order to maintain data integrity. You should also consider that the database for your project could probably be used by other applications in the future which might be based on other technologies than EF.
If you have relations in DB they will automatically be imported in your EF Model but you always have an option to create the associations manually in the EF Designer if you don't have relations in DB.
See How to manually add association in Entity Framework
I'm developing a Java EE JBoss service which will be deployed in two different environments: one using SQL Server as the database, and a different one which uses Oracle 10g.
My database schemas are very similar, except that the primary key columns are identity-auto-increment in SQL Server and generated using sequences in Oracle.
With JPA, is it possible to use a single set of entities with both DB's?
Thanks!
Of course you can, but just specify the generated-value definition for the PK field in XML metadata rather than annotations. Use 2 different "orm.xml" files, so, for example, use "persistenceUnitOracle" for Oracle that references orm-oracle.xml, and "persistenceUnitSqlServer" for SQLServer that references orm-sqlserver.xml