entity-framework-ctp5

Multi-Level Includes in CodeFirst - EntityFrameWork

三世轮回 提交于 2019-11-28 22:26:11
问题 It is working code; IQueryable<Product> productQuery = ctx.Set<Product>().Where(p => p.Id == id).(Include"Contexts.AdditionalProperties.Field"); But you know that it could not produce compile time error if we made mistake in string statement in "Contexts.AdditionalProperties.Field" I would like to write code below; IQueryable<Product> productQuery = ctx.Set<Product>().Where(p => p.Id == id).Include(p => p.Contexts); But above statement could not give chance to define AdditionalProperties and

EF Code First - Include(x => x.Properties.Entity) a 1 : Many association

落花浮王杯 提交于 2019-11-28 18:35:53
Given a EF-Code First CTP5 entity layout like: public class Person { ... } which has a collection of: public class Address { ... } which has a single association of: public class Mailbox { ... } I want to do: PersonQuery.Include(x => x.Addresses).Include("Addresses.Mailbox") WITHOUT using a magic string. I want to do it using a lambda expression. I am aware what I typed above will compile and will bring back all Persons matching the search criteria with their addresses and each addresses' mailbox eager loaded, but it's in a string which irritates me. How do I do it without a string? Thanks

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

a 夏天 提交于 2019-11-28 17:51:57
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 Expression<Func<TModel,TProperty>> . I can get all the Cities for the County no problem: var query = ctx

using Guid as PK with EF4 Code First

末鹿安然 提交于 2019-11-28 17:27:04
I have this class and table: public class Foo { public Guid Id {get;set;} public string Name {get;set;} } create table Foo ( id uniqueidentifier primary KEY DEFAULT (newsequentialid()), name nvarchar(255) ) the problem is that when i try to save new foo the first one goes with the 0000-000-00 ... id and the second also, so I get constraint exception anybody knows a fix ? Devart Have you set Identity StoreGeneratedPattern? You can do it in the OnModelCreating method: modelBuilder.Entity<Foo>().Property(o => o.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity); or using the

Entity Framework Code First - Change Table Column Collation

邮差的信 提交于 2019-11-28 12:02:32
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 Ladislav Mrnka Model builder doesn't allow this but you can create custom database initializer and execute ALTER TABLE command. The example will be the same as this one creating custom index. 来源: https://stackoverflow.com

Circular Reference exception with JSON Serialisation with MVC3 and EF4 CTP5w

主宰稳场 提交于 2019-11-28 10:56:49
I'm having problems with a circular reference when i try and serialise an object returned via EF4 CTP5. Im using the code first approach and simple poco's for my model. I have added [ScriptIgnore] attributes to any properties that provide a back references to an object and annoyingly every seems to work fine if i manually instantiate the poco's, i.e. they serialise to JSON fine, and the scriptignore attribute is acknowledged. However when i try and serialise an object returned from the DAL i get the circular reference exception "A circular reference was detected while serializing an object of

Entity Framework CTP5 Code-First Mapping - Foreign Key in same table

∥☆過路亽.° 提交于 2019-11-28 04:43:22
问题 How would I map something like this using the modelBuilder? Where theres a nullable foreign key referencing the same tables primary key Table: Task taskID int pk taskName varchar parentTaskID int (nullable) FK Task class: public class Task { public int taskID {get;set;} public string taskName {get;set;} public int parentTaskID {get;set;} public Task parentTask {get;set;} } ... modelBuilder.Entity<Task>() .HasOptional(o => o.ParentTask).... 回答1: The following code gives you the desired schema.

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

人走茶凉 提交于 2019-11-28 04:26:45
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! 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(Order=1)] public int MySecondKeyProperty { get; set; } [Key, Column(Order=2)] public string

EF4 Independent Associations - Why avoid them?

匆匆过客 提交于 2019-11-28 01:07:58
问题 I saw this comment on MSDN (link and link): "Note that Independent Associations should often be avoided since things like N-Tier and concurrency becomes more difficult." I'm new to EF4 and I'm building an n-Tier web app. This sounds like an important pitfall. Can someone explain to me what this means? 回答1: I think it's personal preference. Originally, EF was created to only use indep. associations and aligned with a more classic ERM approach. However, most of us devs are so dependent on FKs

Generate money type fields using code first EF CTP5

Deadly 提交于 2019-11-27 22:43:35
In this blog post: EF4 Code First Control Unicode and Decimal Precision, Scale with Attributes , Dane Morgridge used attributes to control the creation of different types on your database. ...And I found this pretty unique BTW!!! How do I generate money type fields in my resulting database using code first API of EF CTP5, if is possible to do it from your model, using conventions or attributes? Sorry about my English is not my main language. Thanks in advance. For example, consider this Invoice class: public class Invoice { public int InvoiceId { get; set; } public decimal Amount { get; set; }