Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

One to many relationship without foreign key

$
0
0

I've problem with mapping ralations, which there is in existing database. 

Two tables: table1 and table2

table1 has fields: table1Id, table1Code, table1Field (table1Id is primary key)

table2 has fields: table2Id, table1Code, table2Field (table2Id is primary key)

And I've ralation one to many between table2 and table1 so I need in table2 object table2.table1 which will be filled by looking for table1 row in table1 by table1Code. Ofcourse I need ICollection<table2> inside table1.

There is reference in database "ALTER TABLE table2 WITH CHECK ADD CONSTRAINT [FK_table2_table1] FOREIGN KEY([table1Code]) REFERENCES table1 ([table1Code])"

I use https://github.com/sjh37/EntityFramework-Reverse-POCO-Code-First-Generator which generates mapping below

HasRequired(a => a.table1).WithMany(b => b.table2).HasForeignKey(c => c.table1Code);

and when try to use it I see that generated SQL compares table1Id with table1Code (I think that it's because of use table1Id as foreign key)

Is it possible to create such mapping between those two tables, which are connected by table1Code?


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>