code-first

Entity Framework CTP5 Code-First: How do I specify the type of the discrimimator column in Table-Per-Hierarchy Mapping?

余生长醉 提交于 2019-12-12 12:23:17
问题 This blog post of the ADO.NET team shows in an example how to define Table-Per-Hierarchy Mapping in the Fluent API of Entity Framework Code-First. This is the (slightly simplified) example: public class Product { public int ProductId { get; set; } public string Name { get; set; } // more properties } public class DiscontinuedProduct : Product { public DateTime DiscontinuedDate { get; set; } } ... and the TPH mapping: modelBuilder.Entity<Product>() .Map<Product>(m => m.Requires("Type")

Entity Framework 6 Creating Two table from the same entity object

空扰寡人 提交于 2019-12-12 11:14:59
问题 I was wondering if it's possible to create two table instance from one defined entity object class. Example: public class EntityA() { public String name {get; set;} public String value {get; set;} } public class MyDbConext : DbContext { public DbSet<EntityA> instance1{ get; set; } public DbSet<EntityA> instance2{ get; set; } } What i'm trying to do is create two instances of Entity A with different table names. Is that possible with code first entity framework? I feel like it's seems tedious

How do I represent an option calculated column with EF Code First?

天大地大妈咪最大 提交于 2019-12-12 09:52:54
问题 I have a situation where I have a table of entries that I'll be querying on, but in some cases I'll have additional information available. For instance, if I have a table of people , I want to be able to search by name, but I also want to store some coordinates and search based on their location, but also expose that distance in the object model. So, for instance, suppose my people table looks something like this: PersonId int Name nvarchar(100) Address nvarchar(100) Latitude float(10,6)

EF Code First, how can I achieve two foreign keys from one table to other table?

好久不见. 提交于 2019-12-12 09:43:21
问题 I've recently downloaded Entity Framework Code First CTP5 , and have a trouble with this scenario. I have two tables as follows: Members table : ID Name Comments table : ID Comment CommentedMemberID CommentMemberID And, the data should be like the following: Members ID Name 1 Mike 2 John 3 Tom Comments ID Comment CommentedMemberID CommentMemberID 1 Good 1 2 2 Good 1 3 3 Bad 2 1 Then, I coded as shown below: public class Member { public int ID {get; set; } public string Name { get; set;}

Entity Framework 4.1 Code First - Define many-to-many using data annotations only

﹥>﹥吖頭↗ 提交于 2019-12-12 08:34:25
问题 Is it possible to define a many-to-many relationship in Entity Framework 4.1 (Code First approach) using Data Annotations only, without model builder? For example, something like: Product = { Id, Name, ... } Category = { Id, Name, ... } ProductCategory = { ProductId, CategoryId } You get the picture. I don't want to have an intermediate entity ProductCategory in the context with two many-to-ones since I don't have any additional data, just the two FKs. Also, I should be able to define table

How do you assign a transaction with EF4 CodeFirst CTP5 without using TransactionScopes?

人走茶凉 提交于 2019-12-12 07:39:23
问题 I am attempting to perform functional tests against a live database, to make sure my linq queries are translating into SQL correctly. I want to do this by using transactions, so that one functional test does not affect another. The problem is, I cannot find any way in the API to utilize transactions correctly. I can retrieve a new DbTransaction via MyDbContext.Database.Connection.BeginTransaction() , however, I cannot find anyway to actually use this transaction. All documentation I can find

Entity Framework CTP5, code-first. Many to many with cascade delete

偶尔善良 提交于 2019-12-12 07:29:35
问题 I have two entities (Customer and CustomerRole) and would like to declare many-to-many relationship between them. I can do using the following code: modelBuilder.Entity<CustomerRole>() .HasMany(cr => cr.Customers) .WithMany(c => c.CustomerRoles) .Map(m => m.ToTable("Customer_CustomerRole_Mapping")); But it creates the relationship (and the third mapping table) with cascade delete switched off by default. How can I tell EF to create the relationship with cascade delete switched on when using

How mature & felxible is the Entity Framework's code-first library?

为君一笑 提交于 2019-12-12 05:45:47
问题 I'm getting ready to do a small, brief architecture spike using the EF code-first approach, introduced by Scott Gu here and here. Before I do, I'd like to know whether it will be worth it. Currently I have a project that uses the EF POCO Generation template, and I'd like to investigate the advantages I can get out of switching to a more pure POCO strategy for the domain model. Particularly, these are the things I'm interested in: Avoiding automatically-generated partial classes with

NotSupportedException: The type A cannot be mapped as definede. Table per Concrete (TPC) EF6

无人久伴 提交于 2019-12-12 05:33:18
问题 I have model like: public abstract class Entity { public int Id { get; set; } } public abstract class Tree : Entity { public Tree() { Childs = new List<Tree>(); } public int? ParentId { get; set; } public string Name { get; set; } [ForeignKey("ParentId")] public ICollection<Tree> Childs { get; set; } } public abstract class Cat : Tree { public string ImageUrl { get; set; } public string Description { get; set; } public int OrderId { get; set; } } public class ItemCat : Cat { ... public

Relationship mapping table with additional properties?

点点圈 提交于 2019-12-12 05:02:34
问题 I have three classes: public partial class Student : Contact { //Inherited from Contact: //public int ContactId { get; set; } //public string FirstName { get; set; } //public string LastName { get; set; } public virtual StudentExam StudentExam { get; set; } } public partial class Exam { public int ExamId { get; set; } public string Title { get; set; } public DateTime Date { get; set; } public virtual StudentExam StudentExam { get; set; } } public partial class StudentExam { public byte Score