entity-framework-4.3

EF 4.3.1 Migration Exception - AlterColumn defaultValueSql creates same default constraint name for different tables

房东的猫 提交于 2019-11-28 00:15:02
I have a DB that I created using the OOB database initializer, and I am using Code First with EF 4.3.1. I wanted to take advantage of the new "IgnoreChanges" flag on the Add-Migration cmdlet, so that I can alter some of my columns and add a default SQL value. Essentially, some of my entities have a column named DateLastUpdated, which I would like to set the DEFAULT to the sql expression GETDATE(). I created the InitialMigration using "add-migration InitialMigration -ignorechanges", and then I added the following to the Up() and Down(): public override void Up() { AlterColumn("CustomerLocations

Is it always better to use 'DbContext' instead of 'ObjectContext'?

时光怂恿深爱的人放手 提交于 2019-11-27 23:52:04
问题 I just downloaded EntityFramework.dll v4.3 . I've found a number of questions that compare DbContext vs. ObjectContext . But most of these are from 2010, or early 2011. I'd like to read more on the subject. Specifically, are there any books on DbContext I can get my hands on? I also want to know, as of today, what are the limitations of DbContext when comparing it to its older brother the ObjectContext ? I realize that DbContext is more compact in that it exposes fewer properties. This

Unidirectional One-To-One relationship in Entity Framework

和自甴很熟 提交于 2019-11-27 21:43:18
Below example of one-to-one relationship throws an exception public class User { public int Id { get; set; } public Address Address { get; set; } } public class Address { public int Id { get; set; } public User User { get; set; } } Exception says: Unable to determine the principal end of an association between the types 'ConsoleApplication1.Address' and 'ConsoleApplication1.User'. The principal end of this association must be explicitly configured using either the relationship fluent API or data annotations. it works if i remove User property from Address but i don't want. How can i have such

Set Command Timeout in entity framework 4.3

别等时光非礼了梦想. 提交于 2019-11-27 21:03:51
I cannot find the a way to set the command timeout of a linq query using entity framework 4.3 and its' DbContext. How do I increase Commandtimeout in entity framework? EDIT I am actually looking for Command Timeout increase. I confused the two, it is the sql command that is timing out not the connection. Thanks bricelam If you're using DbContext, you'll first need to drop down to ObjectContext: ((IObjectContextAdapter)context).ObjectContext.CommandTimeout = 180; I added the command timeout value in my Context class in an attempt to handle longer processing times for some of the stored

How to create database using code first migrations?

自古美人都是妖i 提交于 2019-11-27 20:57:52
问题 I'm having ASP.NET MVC 3 project that uses Entity Framwork 4.3 and its migrations. Now I want Entity Framework to create a database for me using migrations that I have already. When I trying to run Update-Database script it gives me the following: Update-Database -Verbose -ProjectName AssemblyWithMigrations -StartUpProjectName WebProjectAssembly No migrations configuration type was found in the assembly '/* my name of assembly */'. (In Visual Studio you can use the Enable-Migrations command

Mapping a foreign key with a custom column name

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-27 19:59:14
I'm using Entity Framework 4.3 code-first with Oracle. I'm getting the following error: System.InvalidOperationException : The ForeignKeyAttribute on property 'WidgetSequence' on type 'WidgetDistributor.WidgetEntity' is not valid. The foreign key name 'WIDGETSEQUENCE_ID' was not found on the dependent type 'WidgetDistributor.WidgetEntity'. The Name value should be a comma separated list of foreign key property names. My entities are like this: [Table("WIDGETENTITIES")] public class WidgetEntity { [Column("WIDGETENTITY_ID")] public int Id { get; set; } [ForeignKey("WIDGETSEQUENCE_ID")] public

No connection string named 'MyApplicationEntities' could be found in the application config file

风流意气都作罢 提交于 2019-11-27 19:36:26
I just install EF 4.3 and trying to upgrade my project with migration. however I am getting issues with trying to execute add-migration initial to my project via Package Manager console. It is throwing any exception now No connection string named 'MyApplicationEntities' could be found in the application config file. Now my config has it all <connectionStrings> <add name="MyApplicationEntities" connectionString="metadata=res://*/DataModel.csdl|res://*/DataModel.ssdl|res://*/DataModel.msl;provider=System.Data.SqlClient;provider connection string="data source=localhost;initial catalog

Linq when using GroupBy, Include is not working

为君一笑 提交于 2019-11-27 19:22:34
include matchparticipants is not working. It always says Null when I debug. But when I put the GroupBy in comment it works fine. I am using Entity framework 4.3.1 with code-first. Entities: public class Match { [ScaffoldColumn(false)] public int MatchId { get; set; } [Required(ErrorMessage = "Matchtype is a required field")] public int Scheme { get; set; } [Required] [DefaultValue(false)] public bool Finished { get; set; } public int Round { get; set; } // Relations [Required] public Category Category { get; set; } public Official Official { get; set; } public Slot Slot { get; set; } public

Confusion over EF Auto Migrations and seeding - seeding every program start

不羁岁月 提交于 2019-11-27 17:30:49
I recently changed an application from using the following for dev: DropCreateDatabaseIfModelChanges<Context> To using: public class MyDbMigrationsConfiguration: DbMigrationsConfiguration<GrsEntities> { public MyDbMigrationsConfiguration() { AutomaticMigrationsEnabled = true; AutomaticMigrationDataLossAllowed = true; } } In my db context I have: protected override void OnModelCreating(DbModelBuilder modelBuilder) { // Tell Code First to ignore PluralizingTableName convention // If you keep this convention then the generated tables will have pluralized names. modelBuilder.Conventions.Remove

EF (Entity Framework) 4.3 Migration tool does not work on EF 4.1 DB

无人久伴 提交于 2019-11-27 16:45:34
问题 I want to modify one DB which was developed with EF 4.1 (Code First). I upgraded the project into EF 4.3 and follow this steps: http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-automatic-migrations-walkthrough.aspx Everything is going well, but when I want to test on current DB (EF 4.1 Code First), Update-Database raise this error: Cannot scaffold the next migration because the target database was created with a version of Code First earlier than EF 4.3 and does not contain the