entity-framework-ctp5

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

Can I access the discriminator value in TPH mapping with Entity Framework 4 CTP5

怎甘沉沦 提交于 2019-12-18 14:54:56
问题 Using Entity Framework 4 CTP5 Code First and this example Is it possible to access the discriminator value? I would like to use it in a projection like context.BillingDetails.Select(x => new { Number = x.Number, DiscrimitatorValue = /* how do I get the discriminator value? */ }); From this post I understand the discriminator cannot be mapped to a property but is there any other way of accessing it? 回答1: I may be late to the game on this one, but I just added a getter property to the base

LINQ to Entities does not recognize the method

纵然是瞬间 提交于 2019-12-18 04:16:08
问题 I am following this article on MSDN. I ported it to EF Code First. public interface IUnitOfWork { IRepository<Employee> Employees { get; } IRepository<TimeCard> TimeCards { get; } void Commit(); } public class HrContext : DbContext { public DbSet<Employee> Employees { get; set; } public DbSet<TimeCard> TimeCards { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<Employee>() .HasMany(e => e.TimeCards) .WithOptional(tc => tc.Employee); } }

Entity Framework 4 CTP 5 Self Referencing Many-to-Many

爷,独闯天下 提交于 2019-12-18 02:49:38
问题 I have the following scenario in my database. It is a record of Studies and those studies have other studies as prerequisites. In my DB design, it looks like this: And my code looks something like this: public class Study { public int ID { get; set; } public string Topic { get; set; } public byte TypeID { get; set; } public virtual StudyType Type { get; set; } public bool Deprecated { get; set; } public virtual ICollection<Study> Prerequisites { get; set; } } public class StudyType { public

EF CTP5 - Strongly-Typed Eager Loading - How to Include Nested Navigational Properties?

…衆ロ難τιáo~ 提交于 2019-12-17 22:14:21
问题 Attempting to cutover our EF4 solution to EF CTP5, and ran into a problem. Here's the relevant portion of the model: The pertinent relationship: - A single County has many Cities - A single City has a single State Now, i want to perform the following query: - Get all Counties in the system, and include all the Cities, and all the State's for those Cities. In EF4, i would do this: var query = ctx.Counties.Include("Cities.State"); In EF CTP5, we have a strongly typed Include, which takes an

Entity Framework Code First - Change Table Column Collation

Deadly 提交于 2019-12-17 20:17:00
问题 I'm using Entity Framework CTP5 and Code First. I need to change the Collation for a specific column in SQL Server. I believe the default collation is SQL_Latin1_General_CP1_CI_AS, but I need to change this one column colllation to SQL_Latin1_General_CP1_CS_AS (Case Sensitive). Is there a way to use ModelBuilder in Code First to change a specific column collation? BarDev 回答1: Model builder doesn't allow this but you can create custom database initializer and execute ALTER TABLE command. The

in entity framework code first, how to use KeyAttribute on multiple columns

不羁岁月 提交于 2019-12-17 17:36:29
问题 I'm creating a POCO model to use with entity framework code first CTP5. I'm using the decoration to make a property map to a PK column. But how can I define a PK on more then one column, and specifically, how can I control order of the columns in the index? Is it a result of the order of properties in the class? Thanks! 回答1: You can specify the column order in the attributes, for instance: public class MyEntity { [Key, Column(Order=0)] public int MyFirstKeyProperty { get; set; } [Key, Column

Using mvc-mini-profiler database profiling with Entity Framework Code First

醉酒当歌 提交于 2019-12-17 05:04:13
问题 I'm using the mvc-mini-profiler in my project built with ASP.Net MVC 3 and Entity Framework code-first. Everything works great until I attempt to add database profiling by wrapping the connection in the ProfiledDbConnection as described in the documentation. Since I'm using a DbContext, the way I am attempting to provide the connection is through the constructor using a static factory method: public class MyDbContext : DbContext { public MyDbContext() : base(GetProfilerConnection(), true) { }

Using mvc-mini-profiler database profiling with Entity Framework Code First

风流意气都作罢 提交于 2019-12-17 05:03:19
问题 I'm using the mvc-mini-profiler in my project built with ASP.Net MVC 3 and Entity Framework code-first. Everything works great until I attempt to add database profiling by wrapping the connection in the ProfiledDbConnection as described in the documentation. Since I'm using a DbContext, the way I am attempting to provide the connection is through the constructor using a static factory method: public class MyDbContext : DbContext { public MyDbContext() : base(GetProfilerConnection(), true) { }

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")