ef-code-first

Seamless EF Migrations from Staging > Production with Schema Change

一笑奈何 提交于 2020-01-02 05:58:10
问题 I have a simple web app. It consists of an Azure Web App with Staging and Production slots. When there are no DB migrations to consider, I can easily achieve a seamless update by: Deploy App to Staging Swap Staging <> Production Slots This gets trickier when I have a DB migration to handle. Right now what I do is: Deploy App to Staging When deployment is ready, run update-database to Prod (no staging database) Swap Staging <> Production Slots This means that I still effectively have downtime

Seamless EF Migrations from Staging > Production with Schema Change

拥有回忆 提交于 2020-01-02 05:58:09
问题 I have a simple web app. It consists of an Azure Web App with Staging and Production slots. When there are no DB migrations to consider, I can easily achieve a seamless update by: Deploy App to Staging Swap Staging <> Production Slots This gets trickier when I have a DB migration to handle. Right now what I do is: Deploy App to Staging When deployment is ready, run update-database to Prod (no staging database) Swap Staging <> Production Slots This means that I still effectively have downtime

DbUpdateException with entities that do not expose foreign key properties

不羁岁月 提交于 2020-01-02 02:19:08
问题 I have an entity model with User and Person entities, such that each User must be associated with exactly 1 Person , and each Person can be associated zero or 1 User . User (0..1) <-------> (1) Person The association is mapped fluently. Originally I only had it declared on the Person side: private class PersonOrm : EntityTypeConfiguration<Person> { internal PersonOrm() { ToTable(typeof(Person).Name, DbSchemaName.People); // has zero or one User HasOptional(p => p.User) .WithRequired(d => d

Code First Entity Framework adds an underscore to a primary key column name

瘦欲@ 提交于 2020-01-02 02:06:08
问题 I have a fluent mapping of a domain class that defines the names for each column including the primary key which is made up of two columns, NotificationId and IdentityId. These are also foreign keys that point at Notification.Id and Identity.Id respectively. Whenever I use this mapping as part of a query it generates a sql query with an underscore in between Notification and Id (Notification_Id) that is not mentioned anywhere in my mappings. I would expect that there might be some convention

Entity Framework - The foreign key component … is not a declared property on type

与世无争的帅哥 提交于 2020-01-01 23:36:48
问题 I have the following Model public class FilanthropyEvent : EntityBase, IDeleteable { public int Id { get; set; } public string Name { get; set; } public DateTime EventDate { get; set; } public string Description { get; set; } public decimal Target { get; set; } public decimal EntryFee { get; set; } public bool Deleted { get; set; } public ICollection<EventAttendee> EventAttendees { get; set; } } public class Attendee : EntityBase, IDeleteable { public int Id { get; set; } public string Email

Entity Framework - The foreign key component … is not a declared property on type

牧云@^-^@ 提交于 2020-01-01 23:35:28
问题 I have the following Model public class FilanthropyEvent : EntityBase, IDeleteable { public int Id { get; set; } public string Name { get; set; } public DateTime EventDate { get; set; } public string Description { get; set; } public decimal Target { get; set; } public decimal EntryFee { get; set; } public bool Deleted { get; set; } public ICollection<EventAttendee> EventAttendees { get; set; } } public class Attendee : EntityBase, IDeleteable { public int Id { get; set; } public string Email

EF Code first related entities context fail

China☆狼群 提交于 2020-01-01 16:49:29
问题 Dunno how to name this properly. I have two entities in m:n relationship: Member and Role. public class Role { public int Id { get; set; } public string Title { get; set; } public ICollection<Member> MembersInRole { get; set; } } public class Member { public int Id { get; set; } public string Name { get; set; } public string Password { get; set; } public string Email { get; set; } public ICollection<Role> Roles { get; set; } } I have made some seed data: http://i56.tinypic.com/2vjvj1w.png And

Entity Framework 6.1.1 Naming Convention for indexes

心不动则不痛 提交于 2020-01-01 11:55:26
问题 I understand how to add conventions to the code first (with migrations) project. I have successfully managed to perform the table names and even changed GUID Id fields to non-clustered. But I have not found how to change the default index name that EF supplies when no name is given. [Index(IsUnique = true)] public string Code { get; set; } [Index] public string Description { get; set; } I have these two requirements. The top index should be named UX_[schema]_[table]_Code , the second IX_

Can't SaveChanges with Entity Framework in ASP.Net MVC 3 project

混江龙づ霸主 提交于 2020-01-01 10:49:47
问题 Studying asp.net mvc 3 + EF code-first. I am new to both. My example is trivial, but I still can't make it work. Missing something simple and obvious... I've got a class: public class Product { [HiddenInput(DisplayValue = false)] public int ProductID { get; set; } [Required(ErrorMessage = "Please enter a product name")] public string Name { get; set; } [Required(ErrorMessage = "Please enter a description")] [DataType(DataType.MultilineText)] public string Description { get; set; } [Required]

Can't SaveChanges with Entity Framework in ASP.Net MVC 3 project

孤者浪人 提交于 2020-01-01 10:49:21
问题 Studying asp.net mvc 3 + EF code-first. I am new to both. My example is trivial, but I still can't make it work. Missing something simple and obvious... I've got a class: public class Product { [HiddenInput(DisplayValue = false)] public int ProductID { get; set; } [Required(ErrorMessage = "Please enter a product name")] public string Name { get; set; } [Required(ErrorMessage = "Please enter a description")] [DataType(DataType.MultilineText)] public string Description { get; set; } [Required]