entity-framework-4.1

EF 4.1 Code First. Table-per-type inheritance with different primary key name from its base class' primary key name

两盒软妹~` 提交于 2019-12-01 20:29:22
问题 Given this: create table Location( LocationId int identity(1,1) not null primary key, Address nvarchar(max) not null, City nvarchar(max) null, State nvarchar(max) not null, ZipCode nvarchar(max) not null ); create table Park( ParkId int not null primary key references Location(LocationId), Name nvarchar(max) not null ); I tried this mapping: modelBuilder.Entity<Location>(); modelBuilder.Entity<Park>().ToTable("Park"); modelBuilder.Entity<Park>().Property(x => x.LocationId).HasColumnName(

EF 4.1 Code First. Table-per-type inheritance with different primary key name from its base class' primary key name

孤人 提交于 2019-12-01 19:45:29
Given this: create table Location( LocationId int identity(1,1) not null primary key, Address nvarchar(max) not null, City nvarchar(max) null, State nvarchar(max) not null, ZipCode nvarchar(max) not null ); create table Park( ParkId int not null primary key references Location(LocationId), Name nvarchar(max) not null ); I tried this mapping: modelBuilder.Entity<Location>(); modelBuilder.Entity<Park>().ToTable("Park"); modelBuilder.Entity<Park>().Property(x => x.LocationId).HasColumnName("ParkId"); Unfortunately that didn't work. using (var db = new Ef()) { var park = new Park { Name = "11th

entity framework custom data type mapping

会有一股神秘感。 提交于 2019-12-01 19:24:48
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=True;" + "multipleactiveresultsets=True;App=EntityFramework") { } protected override void

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

别说谁变了你拦得住时间么 提交于 2019-12-01 18:49:09
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 { public virtual long Id { get; set; } public virtual string Title { get; set; } public virtual

DBContext lazyloadingenabled set to true still loads related entities by default

女生的网名这么多〃 提交于 2019-12-01 18:03:47
问题 LazyLoadingEnabled is specifically set to true to prevent the related entities from loading in the context I'm using. A drug class has a list of drugidentity objects in it. public class Drug { public virtual List<DrugIdentity> DrugIdentities { get; set; } } A specific configuration for the class sets the key and hasmany relationship if I wanted to include the related entity to be loaded. public DrugConfiguration() { this.HasKey(d => d.DrugID); this.HasMany(d => d.DrugIdentities).WithOptional

DBContext lazyloadingenabled set to true still loads related entities by default

╄→尐↘猪︶ㄣ 提交于 2019-12-01 17:47:40
LazyLoadingEnabled is specifically set to true to prevent the related entities from loading in the context I'm using. A drug class has a list of drugidentity objects in it. public class Drug { public virtual List<DrugIdentity> DrugIdentities { get; set; } } A specific configuration for the class sets the key and hasmany relationship if I wanted to include the related entity to be loaded. public DrugConfiguration() { this.HasKey(d => d.DrugID); this.HasMany(d => d.DrugIdentities).WithOptional(d => d.Drug).Map(d => d.MapKey("DrugID")); } When the Drug context is loaded using a linq query the

Entity Framework Code First IQueryable

ε祈祈猫儿з 提交于 2019-12-01 17:09:49
I am using Entity Framework Code First and ran into a small road block. I have a class "Person" defined as such: public class Person { public Guid Id { get; set; } public virtual ICollection<History> History { get; set; } } and a class "History" defined as such: public class History { public Guid Id { get; set; } public virtual Person Owner { get; set; } public DateTime OnDate { get; set; } } However, when I call: IEnumerable<History> results = person.History .OrderBy(h => h.OnDate) .Take(50) .ToArray(); It appears to pull all of the history for the person, then order it and such in memory.

Problem modelling relationship in Entity Framework using code first

我的未来我决定 提交于 2019-12-01 16:05:43
I'm trying to learn code first within the Entity Framework and am having trouble modelling a relationship. It's a basic HR database which for the sake of this has two entities, Employees and Departments. The Employee belongs to a department and the department has a Team Administrator and a Manager, both of whom are in effect employees. I've tried to model this using the following: EMPLOYEE public int? DepartmentID { get; set; } public virtual Department Department { get; set; } Context: modelBuilder.Entity<Employee>().HasOptional(x => x.Department); DEPARTMENT public class Department {

Error loading EntityFramework 4.3.1

ε祈祈猫儿з 提交于 2019-12-01 15:58:39
I created an MVC application in C#. I created a new project in my solution called PhoneDomain. The purpose of this is to separate my data and domain layer from the actual problem. I right clicked on the project and went to "Add Library Package Reference" and I attempted to add the EntityFramework package (version 4.3.1). It said " Operation Failed " " This package contains an init.ps1 file and needs to be installed from the Package Manager Console ". So I opened the Package Manager Console in Visual Studio and typed the following into the console window: install-package EntityFramework

Entity Framework Code First and Collections of Primitive Types

安稳与你 提交于 2019-12-01 15:32:51
When creating POCO classes that contain collections of primitive types and are persisted by EF Code First, the best advice I have found so far is to create a new class that has an ID plus the primitive type: Entity Framework and Models with Simple Arrays If I now have several classes that require properties of type ObservableCollection<string> and replace them with ObservableCollection<EntityString> (where EntityString is a custom type with an Id and a string property), I end up with a table EntityString that has multiple foreign key columns, one for each property of type ObservableCollection