entity-framework-5

Entity Framework 5 Multiple identity columns specified for table. Only one identity column per table is allowed

不羁岁月 提交于 2019-12-03 06:38:38
问题 I am creating this model as part of my code first entity framework public class NewUserRegistration { [Key] public int NewUserRegistrationId { get; set; } } Using the Update-Database -Verbose -Force command in the Package Manger ConsoleI get this exception during the this bit of the update Applying automatic migration: 201211252223088_AutomaticMigration. ALTER TABLE [dbo].[NewUserRegistration] ADD [NewUserRegistrationId] [int] NOT NULL IDENTITY System.Data.SqlClient.SqlException (0x80131904):

Entity Framework 5.0 PostgreSQL (Npgsql) default connection factory

烂漫一生 提交于 2019-12-03 06:30:33
I'm trying to get EF 5.0 code first working with PostgreSQL (Npgsql provider). I have Npgsql 2.0.12.1 installed via NuGet (referenced assembly is 2.0.12.0 though). I have Npgsql declared in app.config (both default connection factory and provider factory): <entityFramework> <defaultConnectionFactory type="Npgsql.NpgsqlFactory, Npgsql, Version=2.0.12.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" /> </entityFramework> <system.data> <DbProviderFactories> <add name="Npgsql Data Provider" invariant="Npgsql" description="Data Provider for PostgreSQL" support="FF" type="Npgsql.NpgsqlFactory,

Entity Framework Code-First Migrations - Cannot drop constraint because it doesn't exist (naming convention from 4.3 to 5.0)

五迷三道 提交于 2019-12-03 05:50:14
Was previously using EF 4.3 and upon upgrading to 5.0 I find out the Indexes, FK constraints, and PK constraints all have had their naming conventions changed to include dbo (eg. PK_Users has now become PK_dbo.Users) Now anytime I make a change to the model and it needs to change a table that has these in it, it always says it can't drop constraint because it can't find it. I just want it so that when it tries to drop a constraint/index/key it first checks to see if the pre-5.0 naming one exists and if so drop it, but still re-create it using the new 5.0 naming conventions. The naming

Ignore TransactionScope for specific query

断了今生、忘了曾经 提交于 2019-12-03 05:39:59
问题 I'm looking for a way to execute a query while a TransactionScope is alive, and ignore the TransactionScope - basically, I want to execute this particular query no matter what. I'm using EF code-first, and the way the application is designed, a new data context is opened many times throughout a single call, each with its own changes, and all of those are contained within a single TransactionScope, which has Complete() called at the end assuming no failures. Inside of the context we've

Consolidating EF migrations into new InitialCreate

你说的曾经没有我的故事 提交于 2019-12-03 05:30:00
问题 I have been using EF migrations for some time now and have more than 100 migration files in my project. I would like to consolidate these into a single migration before moving forward - ie I want to replace the existing InitialCreate migration with a new version that takes all my subsequent changes into account so I can then delete all the other migration files. I do this very easily if I am not concerned with losing all the data in the DB, but I am. How can I achieve this whilst keeping all

Code-first: Mapping entities to existing database tables

元气小坏坏 提交于 2019-12-03 05:25:07
I am using Entity Framework 6 code-first with an existing database, but having problems mapping my entities to the database tables. Normally, I would use database-first approach and have my entity and context code generated, but using the designer has become a huge pain. I have set Database.SetInitializer(null) as I do not want EF to change my schema. Database schema: Code-first: public class Project { public int ProjectId { get; set; } public string Name { get; set; } public string Description { get; set; } } public class ReleaseControlContext : DbContext { public ReleaseControlContext() :

ASP.NET MVC 4, Migrations - How to run 'update-database' on a production server

僤鯓⒐⒋嵵緔 提交于 2019-12-03 04:14:51
问题 I can use package manager to run 'update-database -verbose' locally. Probably a stupid question but I can't find it online - once my website is deployed - how can I run this manually on the server? Secondarily - what other strategies would you recommend for deploying database migrations to production - and how would they be preferable? Thanks 回答1: You have a couple of options: You could use update-database -script to generate the SQL commands to update the database on the server You could use

How to switch between test and production databases with Entity Framework 5

谁都会走 提交于 2019-12-03 04:04:52
I've got separate test and production databases for my ASP.NET MVC 4 application. Using Entity Framework 5, how can I have Entity Framework switch between these two databases programmatically? The application knows which database should be used at which time, so I just need for the application to be able to change Entity Framework so that it utilizes the correct database at the correct time. Anyone know how to accomplish this and/or have a good example available? EDIT: due to how my app is arranged, I am going to need to utlize GvM's answer. The last remaining thing, however, is that I don't

Entity Framework 5, switch from code first to database first?

旧城冷巷雨未停 提交于 2019-12-03 03:44:12
I've already created a database using code first. It worked well. Many changes have since been made to the database outside Visual Studio. So many that any attempt at migration generates errors. So my question is, is there a way to switch a solution from code first to database first? This should be easy, just create a new, database first model and delete your code first model. Most of your code will compile just fine if you are in the same namespace and take care of naming your context in the same way. Switching to database first however, makes you lose the ability to migrate which is a solid

After updating Entity Framework model, Visual Studio does not see changes

牧云@^-^@ 提交于 2019-12-03 02:57:36
问题 If I do any changes to my EF 5.0 model, VS does not seem to see the changes. I have tried adding a new table, which shows up fine in the model, but then if I try to use it somewhere the table does not show up in intellisense and I can't use it. I have also tried changing datatypes of a column, which again shows up fine if I look at the .edmx model file, but visual studio will still give me compiler errors on that field because I am trying to assign the incorrect datatype. If I delete the EDMX