Wednesday, 15 April 2015

c# - I have more columns that I want on my database with my EF Code First model -


I'm developing an Entity Framework code prior to 6.1.2 with the .Net Framework 4.5.1 and C #.

I have these two tables:

  public class code {public string code {get; Set; } Public at BATCH_ID {get; Set; } Get public byte CODE_LEVEL { Set; } Public byte COMMISIONING_FLAG {get; Set; } Public Virtual AGGREGATION_CHILDS Integration child {get; Set; } Public Virtual List & lt; AGGREGATION_CHILDS & gt; Aggregation child {receive; Set; } Public Virtual Batch Batch {get; Set; }} Public class AGGREGATION_CHILDS {public string CODE {get; Set; } Public string CODE_CHILD {get; Set; } Public At Position {Received; Set; } Public virtual code aggregation {received; Set; } Public Virtual Code Code {get; Set; }}  

and their unit framework map:

  class code configuration: EntityTypeConfiguration & lt; CODES & gt; {Public Code Configuration () {HasKey (c => c.CODE); Property (C => C.CODE). HASDatabaseGeneratedOption (DatabaseGeneratedOption.None); Property (C = & CO; CAWEEDE). Hasmaxleenth (20); Property (c => c.BATCH_ID) .IsRequired (); Property (C => C. CODE_LEVEL) .IsRequired (); Property (C = & gt; c.COMMISIONING_FLAG) .IsRequired (); HasRequired (c = & gt; c.batch) Together with many (B = & gt; B. Cds) .User's (C => C. BATHHID); }} Class AGGREGATION_CHILDS configuration: EntityTypeConfiguration & lt; AGGREGATION_CHILDS & gt; {Public AGGREGATION_CHILDSConfiguration () {HasKey (ag_ch = & gt; new {ag_ch.CODE, ag_ch.CODE_CHILD}); Asset (AG_C => ag_ch.CODE). Hassadabase Generated ops (Database Generation. Non); Property (AG_C => AG_CH.CODDCCHIL). HASMXLMDent (20) ISRAEFair (); HasRequired (ag_ch = & gt; ag_ch.Aggregation). With optical (c => c.AggregationChild); HasRequired (ag_ch = & gt; ag_ch.Code). Multiple (C => c.AggregationChildren). HesForeignKey (ag_ch = & gt; ag_ch.CODE_CHILD); }}  

I want to create these two tables with these relationships:

  Make Table [DBO]. [AGGREGATION_CHILDS] ([CODE] [Nvwarchar] (20) No, no [CODE_CHILD] [Nwarvcr] (20) No, no, [position] [Int], Contrastent [Pike_ AGGREGATION_CHILDS] primary key Clastr ([CODE] ASC , [CODE_CHILD] ASC), CONSTRAINT [FK_AGGREGATION_CHILDS_AGGREGATIONS] [key] [code]] references [code] ([cODE]), CONSTRAINT [FK_AGGREGATION_CHILDS_CODES] Create foreign key ([CODE_CHILD]) references [code] ([cODE]) table [DBO]. [code] ([cODE] [nvarchar] (20) nOT NULL, [BATCH_ID] nOT NULL, [CODE_LEVEL] [Tinyint] nOT NULL, [COMMISIONING_FLAG] [Tinyint] nOT NULL, constraint [PK_CODES] pRIMARY KEY Cluster ([code] ASC) int, constraint [FK_CODES_BATCHES] foreign key ([BATCH_ID]) References [DBO]. [Batches] ([id]))  

But I get it: Enter image details here

Any advice?

You can use the attribute Notmapped

will not create an area on DB.

Once a foreign key is declared, and the index field is used. You can control the foreign key field name or you .hasForeignKey (ag_ch = & gt; ag_ch.CODE_CHILD);

Do not forget that EB can use the EE power tool to reverse the first code to be engineered to DB. So if you have a simple DB sample you can make that code first.


No comments:

Post a Comment