entity-framework-4.1

Entity Framework 4.1 : The navigation property 'BusinessUser' declared on type 'Login' has been configured with conflicting multiplicities

我的未来我决定 提交于 2019-12-20 02:43:24
问题 I am having two entities BusinessUser { Id(PK), Name,...} Login { BusinessUserID(PK, FK), Email, Password, etc...} Relationship between BusinessUser and Login is one-to-zero/one . I am having following configurations In BusinessUser EF configuration class this.HasOptional(bu => bu.LoginInfo) .WithOptionalPrincipal(l => l.BusinessUser); In Login EF configuration class this.HasRequired(l => l.BusinessUser) .WithOptional(bu => bu.LoginInfo); I am getting following exception The navigation

Deleting in EF Code first causes navigational properties to be set to null and empty

本秂侑毒 提交于 2019-12-20 01:13:37
问题 I noticed something interesting when I was performing a delete using EF code first. I use the following domain model: public class User { public virtual long Id { get; set; } public virtual string Name { get; set; } public virtual ICollection<Playlist> Playlists { get; set; } } public class Playlist { public virtual long Id { get; set; } public virtual string Title { get; set; } public virtual User User { get; set; } public virtual ICollection<Track> Tracks { get; set; } } public class Track

entity framework custom data type mapping

岁酱吖の 提交于 2019-12-20 01:07:28
问题 Given this code: public class Car { public virtual int CarId { get; set; } public virtual string TypeName { get; set; } public ConvertableNullable<double> Price { get; set; } } Where the ConvertableNullable is just a workaround to Nullable , but it doesn't inherit from it. Now, this my simple context, where i map, the car class to entity, and map every property of it public class MyDBContext : DbContext { public MyDBContext() : base( "data source=.;initial catalog=newDB1;integrated security

Switch connection strings based on environment with EF 4.1/DbContext

久未见 提交于 2019-12-19 08:54:51
问题 I have seen several posts about this but have not been able to create a usable solution from the responses. Perhaps due to a lack of understanding. The hosting provided requires that an identical code base be used on staging and production, including connection string. How do I switch the connection string for DbContext? I understand I can do something like this: public FooEntities() : base("ApplicationServices") { } But this is not dynamic - it merely sets it at runtime. So how would I

EF 4.1: Removing child object from collection does not delete it - why?

强颜欢笑 提交于 2019-12-19 08:05:58
问题 I have a some error : EF 4: Removing child object from collection does not delete it - why? when i remove a child from the parent that the child is deleted when i call SaveChanges() , it gives the follow error message: The operation failed: The relationship could not be changed because one or more of the foreign-key properties is non-nullable. When a change is made to a relationship, the related foreign-key property is set to a null value. If the foreign-key does not support null values, a

EF 4.1: Removing child object from collection does not delete it - why?

天涯浪子 提交于 2019-12-19 08:05:33
问题 I have a some error : EF 4: Removing child object from collection does not delete it - why? when i remove a child from the parent that the child is deleted when i call SaveChanges() , it gives the follow error message: The operation failed: The relationship could not be changed because one or more of the foreign-key properties is non-nullable. When a change is made to a relationship, the related foreign-key property is set to a null value. If the foreign-key does not support null values, a

Is it possible to directly reference a many-to-many table using entity framework, code first

隐身守侯 提交于 2019-12-19 05:11:04
问题 I am using the entity framework and modelling a many-to-many relationship. I have created the relationship between the two entities using the fluent API (let's say users and groups): this.HasMany(t => t.Users) .WithMany(t => t.Groups) .Map( m => { m.ToTable("GroupMembers"); m.MapLeftKey("Group_Id"); m.MapRightKey("User_Id"); }); This works great, but I'd like to also be able to reference the GroupMembers table directly. To do that, I have something like: [Table("GroupMembers")] public class

DeleteObject method is missing in Entity Framework 4.1

限于喜欢 提交于 2019-12-19 04:15:23
问题 This is driving me crazy. I am getting error that object doesn't contain definition for DeleteObject. Here is my line of code that produces an error: ctx.Tanks.DeleteObject(Tank); I tried to reference another object from another edmx file that my friend has created and then everything is fine, DeleteObject exists. I don't think I miss any references in my project. And project itself contains edmx file and I used DBContext to create POCOs. Any ideas? 回答1: The DbContext API defines DbSet s not

Entity Framework + Multilevel Inheritance + EF Code first

拟墨画扇 提交于 2019-12-19 04:09:15
问题 I'm trying to set up a TPC inheritance using Code First. I have a three level heirarchy. Abstract class A, concrete class B inherits from A and a class C inherits from B. Class A properties: ID, CreatedBy and CreatedOn. Class B properties: FirstName, LastName, BirthDate Class C properties: Appointmentdate, Status I want tables for class B and class C to be created in the database with identity generated by the database. I have following code in my context class: public DbSet<B> BList { get;

EF 4.1 RC: Weird Cascade Delete

蹲街弑〆低调 提交于 2019-12-19 03:39:17
问题 I have to admit, the features of EF 4.1 RC Codefirst, DataAnnotations and FluentAPI are still overwhelming to me. Sometimes I really don't know what I am doing ;-) Please see the following POCOs: public class Country { [Key] public Guid ID { get; set; } [Required] public virtual Currency Currency { get; set; } } public class Currency { [Key] public Guid ID { get; set; } public virtual ICollection<Country> Countries { get; set; } } The general idea: Every country needs to have a currency. But