c# - How to use NotMapped Properties in a Composite Foreign Key -


i'm creating codefirst database ef project. database being generated unable alter in anyway. have manually created of relationships between tables, have hit wall table.

have 2 tables

t1: fk3 t2: pk1 pk2 pk3 

the relationship between t1: fk1 fk2 hard coded logic. because table t1 fk1 = "foo" , fk2 = "bar"

i've created

t1 [notmapped] fk1 {get {return "foo"}} [notmapped] fk2 {get {return "bar"}} 

mapped fluent api

modelbuilder.entity<t1>     .hasrequired<t2>     .withmany()     .hasforeignkey(f => new {f.fk1, f.fk2, f.fk3 }) 

i error:

the foreign key component 'fk1' not  declared property on type 't1'. verify has not been      explicitly excluded model , valid primitive property. 

how can create relationship? i've tried dataannotations fluentapi doesn't seem handle it.

you can't use [notmapped] properties keys. not mapped means exaclty - "this c# code wont mapped database".

you can use [databasegenerated(databasegenerationoption.computed)] , calculate values on database : custom sequence string sql identity column

ps.: hazzle free way declare foreign key [foreignkey] , use int hold ids.


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -