entity-framework-ctp5

Entity Framework 4 - TPT Inheritance in Features CTP5 (code first): rename foreign key column on inherited table

ぐ巨炮叔叔 提交于 2019-12-07 08:14:32
I'm trying to convert an xml Entity Framework model to Code First (CTP5) one. I have to model a hierarchy which fits quite well the TPT pattern. The only problem I have is that the primary key/foreign key of the "inheriting" table has a different name from the primary key of the base class. These are the relevant fields of the involved tables CREATE TABLE site.Domains ( ID INT NOT NULL PRIMARY KEY, Domain NVARCHAR(128) NOT NULL ) CREATE TABLE site.MainSites ( FKDomainID INT NOT NULL PRIMARY KEY REFERENCES site.Domains(ID) ) CREATE TABLE site.SisterSites ( FKDomainID INT NOT NULL PRIMARY KEY

EF CTP5 - Context Inheritance Across Multiple Assemblies

一曲冷凌霜 提交于 2019-12-06 14:40:16
I have two assemblies, each with models and a model context. The first assembly model context is derived from DbContext. The second assembly model context is derived from the first assembly model context. This works, except the database generation fails because the first assembly models aren't considered when generating the database. Is there a way to ensure that the first assembly models are properly considered during database generation? I solved this by loading the other assembly's metadata into the underlying ObjectContext's MetadataWorkspace within the context's constructor: namespace

Generics and Entity Framework: How do I return a different type depending on a column value

风格不统一 提交于 2019-12-06 06:43:44
问题 We have a Persons table which stores different types of persons (Buyer, Seller, Agent, etc). Our ORM is Entity Framework CodeFirst (CTP5). We're using the repository pattern for good TDD and mocking. In the PersonRepository I want to return a specific type so I can do things like this: Agent a = repository.Get<Agent>(5005); // Where 5005 is just an example Id for the person a.SomeAgentProperty = someValue; Buyer b = repository.Get<Buyer>(253); // Again, a simple PersonId. b.SomeBuyerProperty

Entity Framework CTP5 Code-First: Mapping a class with multiple collections of another class

99封情书 提交于 2019-12-06 02:31:21
问题 With EF CTP5 Code-First I am trying to map a class model which contains multiple collections in one class pointing to another class. Here is an example of what I mean: public class Company { public int CompanyId { get; set; } public IList<Person> FemaleEmployees { get; set; } public IList<Person> MaleEmployees { get; set; } } public class Person { public int PersonId { get; set; } public Company Company { get; set; } } If I let the database create from this model with a DbContext without

entity framework ctp5 get unproxied entity

喜欢而已 提交于 2019-12-05 18:25:21
EF CTP 5. I have a single instance where I would like to get the unproxied entity. I can't seem to find a way to do this. I don't want to disable proxy creation all together, just need it for this one query. Can anyone help? Here is a simple example: var myEntity = DbContext.Entities.Find(1); var unproxy = myEntity...? I believe the only possibility is to create new instance of DbContext and turn proxy creation off just to execute this query. The reason is that DynamicProxy is type created in runtime which derives from your original entity type and adds tracking and lazy loading functionality.

EF Linq to entities query generating UNION for TPC CTP5 code-first entity

依然范特西╮ 提交于 2019-12-05 14:56:45
I have the following entities: public class User { public int Id { get; set; } public string Name { get; set; } } public class HappyUser : User { public bool IsHappy { get; set; } } I am configuring the entities using Table Per Concrete Type (TPC) in order to generate a User table and a HappyUser table. I want the HappyUser table to include the properties of the User class, and I don't want any relationship between the two tables. I configure the entities as follows: public class UserTest : DbContext { public DbSet<User> Users { get; set; } public DbSet<HappyUser> HappyUsers { get; set; }

EF Code-First - Mapping stored procedures

我与影子孤独终老i 提交于 2019-12-05 12:29:22
I'm trying to implement nested sets in my database model. To make it easy to use I would like to create stored procedures for insert/update/delete operations on my tree nodes to keep my tree in a valid state. Is it possible to create mapping of the stored procedures in the current version of code-first model? I mean that my stored procedures will be called when for example, new entity will be added to the dbcontext. Code First in Entity Framework does not support Stored Procedure by default. As there is no designer we cannot even map our stored procs to the entity. There are a many scenario we

How to eager load child entities using repository pattern

谁说胖子不能爱 提交于 2019-12-05 00:00:54
问题 I have an entity named Tour which can have many Agents . I am able to add agents, but I cannot remove them. // _repo is injected.... var tour = _repo.GetById(tourId); tour.AddAgent(new Agent(tour.TourId)); When I attempt to call the Tour.RemoveAgent() method nothing is actually removed. I set a breakpoint inside the Tour.RemoveAgent() method I see that the _agents property has a count of 0 . tour.RemoveAgent(agentId); // This doesn't work because _agents is empty Do I have to do something

Generics and Entity Framework: How do I return a different type depending on a column value

心不动则不痛 提交于 2019-12-04 12:31:18
We have a Persons table which stores different types of persons (Buyer, Seller, Agent, etc). Our ORM is Entity Framework CodeFirst (CTP5). We're using the repository pattern for good TDD and mocking. In the PersonRepository I want to return a specific type so I can do things like this: Agent a = repository.Get<Agent>(5005); // Where 5005 is just an example Id for the person a.SomeAgentProperty = someValue; Buyer b = repository.Get<Buyer>(253); // Again, a simple PersonId. b.SomeBuyerProperty = someOtherValue; The idea is that I know what kind of person I'm getting when I get it from the

Entity Framework CTP5 Code-First: Mapping a class with multiple collections of another class

一个人想着一个人 提交于 2019-12-04 09:12:47
With EF CTP5 Code-First I am trying to map a class model which contains multiple collections in one class pointing to another class. Here is an example of what I mean: public class Company { public int CompanyId { get; set; } public IList<Person> FemaleEmployees { get; set; } public IList<Person> MaleEmployees { get; set; } } public class Person { public int PersonId { get; set; } public Company Company { get; set; } } If I let the database create from this model with a DbContext without further customization, like so: public class MyContext : DbContext { public DbSet<Company> Companies { get;