How do I map collection for non primary key in Entity Frame 4.0 Code First CTP4? -


I am trying to map an existing heritage database in this example, there are several cities near a country.

The problem is that the foreign key on the city table is not the primary key of the country table

table definitions

  CREATE TABLE [dbo]. [CD_Country] ([ID] [int] identified (1,1) NOT NULL, [code] [four] (2) is not NULL, [name] [Nvarchar] (50) NULL, Knstrent [PK_CD_Country] primary key Clastr ( [ID] with ASC) (Pad_aiandiaks = off, Stetisiks_anoarisiompiuti = off, Aijianoarudiupi_kea = off, ALLOW_ROW_LOCKS = oN, ALLOW_PAGE_LOCKS = current) [primary]) [primary] CREATE TABLE at [dbo]. [CD_City] ([id] [int] identification (1,1) zero, [code] [four] (no) NULL, [name] [nvarchar] (50) No, not convert, [Contra QD] [ four] (2) taps, Contrastent [Pikeseedeediti] primary key Clastr ([ID] with ASC) (Piadi_aiandiaks = off, Stetisiks_anoarisiompiuti = off, Aijianoaraiudeepiukewai = off, ALLOW_ROW_LOCKS = oN, ALLOW_PAGE_LOCKS = oN) [primary]) on [ Primary]  

I am trying to do something like this but I get an exception.

"" E-mapping of navigation property 'country' is not valid for joining the 'CDCount' table. Each key property from type 'Test_SOLEF.City' should be included in the mapping once. "Public static class test {public using static void ({{TestEFContext reference = new TestEFContext ()) {foreach (country.Countries.ToList in country ()} { Console.WriteLine (String.Format ("{0} is {1} cities.", Country.Name, country.Cities.Count))}}}} public class TestEFContext: DbContext {public IDbSet & lt; country & gt; ; get coutries {; set;} public IDbSet & LT; City & gt; set cities {get;} public TestEFContext () {ObjectContext.ContextOptions.LazyLoadingEnabled = true} protected override void OnModelCreating (System.Data.Entity.ModelConfiguration. ModelBuilder ModelBuilder) {// City Model Producer. Antity & lt; Iti & gt; () .HasKey (p = & gt; Piaiaidi) .MapSingleType () .ToTable ( "CD_City"); MO DelBuilder.Entity & lt; City & gt; (). Property (C = & gt; C .Id) .IsIdentity (); modelBuilder.Entity & LT; City & gt; () .HasOptional (c = & gt; c.Country) .WithMany (c = & gt; c.Cities) .map ( "CD_Country" , (City, country) = & gt; new {countrycode = city. Country code, code = country.code}); // Country Model Builder. Anti Lieutenant; Country & gt; () .HasKey (P => PIID) .MAPSingleType () .ToTable ("CD_Country"); }} Public square city {public id id (get; set;} public string code {get; set;} public string name {get} set;} public string country code {get} set;} public virtual country country {get set; Public class country {public} id {get} set;} public string code {get; set;} public string name {get; set;} public virtual iconlank official reply from Microsoft

"non-prax with FK There is something in the key that is not currently supported by the entity framework, but there is something we are working on.

Thanks, Arthur "

Forums Posts < / P>


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -