ef-code-first

EF5 Code First and RIA Services Silverlight “Object reference not set to an instance of an object” error building client

点点圈 提交于 2020-01-13 10:04:26
问题 I am working on setting up a new project using Code First for entity framework 5 in silverlight using RIA services. I have created a test project due to some issues I have encountered and will post the code below. Namely, I get an 'Object reference not set to an instance of an object' error anytime I attempt to build the silverlight client project which should generate the client proxy classes. Just to be clear, this error is not while running or debugging the application, but when building

EF5 Code First and RIA Services Silverlight “Object reference not set to an instance of an object” error building client

夙愿已清 提交于 2020-01-13 10:04:16
问题 I am working on setting up a new project using Code First for entity framework 5 in silverlight using RIA services. I have created a test project due to some issues I have encountered and will post the code below. Namely, I get an 'Object reference not set to an instance of an object' error anytime I attempt to build the silverlight client project which should generate the client proxy classes. Just to be clear, this error is not while running or debugging the application, but when building

Selectively Disabling Cascade Delete on Many-to-Many Link Table

放肆的年华 提交于 2020-01-13 08:49:31
问题 Is it possible to selectively remove the Cascade Delete option on an automatically-generated many-to-many link table in Entity Framework 5 Code First? Here's a simple example which needs it: public class Parent { public int Id { get; set; } public virtual IList<ChildA> As { get; set; } public virtual IList<ChildB> Bs { get; set; } } public class ChildA { public int Id { get; set; } [Required] public virtual Parent Parent { get; set; } public virtual IList<ChildB> ChildBJoins { get; set; } }

Downgrade (Rollback) Database with code-first in production environment

让人想犯罪 __ 提交于 2020-01-13 08:04:23
问题 I have a web application that I install on my customers' computers for their inner use. I use C# MVC5 and code-first Entity Framework. I used automatic migration=true but I stopped and set it to false. I installed it on a production environment (release) - with a deploy-package (no Visual Studio). I have a customer with the application - version 1. Now I want to upgrade to version 2. I want to enable to upgrade the App's DB (in production file, with CMD installation from a package), but to

Downgrade (Rollback) Database with code-first in production environment

孤人 提交于 2020-01-13 08:04:03
问题 I have a web application that I install on my customers' computers for their inner use. I use C# MVC5 and code-first Entity Framework. I used automatic migration=true but I stopped and set it to false. I installed it on a production environment (release) - with a deploy-package (no Visual Studio). I have a customer with the application - version 1. Now I want to upgrade to version 2. I want to enable to upgrade the App's DB (in production file, with CMD installation from a package), but to

Entity Framework does not update an auto-increment field of a computed key in mySql

倾然丶 夕夏残阳落幕 提交于 2020-01-13 07:07:10
问题 I'm trying to save an entity using entityframework, although the EF is not update the auto-increment field public class Address { public int Id { get; set; } public int DatacenterId { get; set; } public virtual Datacenter Datacenter { get; set; } } public class AddressMapping : EntityTypeConfiguration<Address> { public AddressMapping() { this.HasKey(k => new { k.Id, k.DatacenterId }); this.HasRequired(itr => itr.Datacenter) .WithMany() .HasForeignKey(fk => fk.DatacenterId); this.Property(p =>

Entity Framework taking a lot of time initializing model

邮差的信 提交于 2020-01-13 05:44:32
问题 I'm facing an issue with EF taking a lot of time (spanning hours) to initialize models. The model is as given below. There are around 20 classes which are derived from A1, and about 30 classes which derive from A2. I had to move from TPT to TPH strategy to fix an issue related to memory usage. And since then I'm trying to figure out this issue. The issue is produced by just creating a single instance of type 'A', adding it to a List<A> property of another entity and committing those changes.

Entity Framework 5 - Enum based Discriminator for derived classes

孤者浪人 提交于 2020-01-12 14:34:09
问题 I have the following (abbreviated for clarity) - an enum, a base class with that enum, and two derived classes that set the enum to a specific value. public enum MyEnum { Value1, Value2 } public class MyBaseClass { public MyEnum { get; protected set; } } public class DerivedOne: MyBaseClass { public DerivedOne { MyEnum = MyEnum.Value1; } } public class DerivedTwo: MyBaseClass { public DerivedTwo { MyEnum = MyEnum.Value2; } } What I want to do, is have Entity Framework 5 automatically

EF 6 Code First Stored Procedure - Read Only

放肆的年华 提交于 2020-01-12 14:21:06
问题 I have searched a few posts, but have come up short. I am using EF6 code first trying to get results from a stored procedure that is already setup in a database. My application is simple, it takes data from two different servers, performs some business logic, and then shows the user. I can use the .edmx file fine, which maps the function in the xml file. When I use Power Tools to show myself the XML file I do not see the function import from my code below so I am either missing a setup or I

Querying Many to Many and Conditional Where

限于喜欢 提交于 2020-01-12 07:54:16
问题 Within my Context file, I set up a many to many relationship between my Location class and Program class. protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity<Location>() .HasMany(u => u.Programs) .WithMany(r => r.Locations) .Map(m => { m.ToTable("LocationsPrograms"); m.MapLeftKey("LocationId"); m.MapRightKey("ProgramId"); }); } I'm creating a search/filter form where the user will need to be able to filter the locations by selecting a program. My thought