.net - Entity framework specify string for dependant column without database key -
in ef there way specify relationship between 2 tables when there no relationship defined in database , 1 of related columns specific string/hard-coded value?
lets have document object , can have various stages of approval , category. table might like
documentid, documentname, documentstate, documentcategory
with following document data:
1, test document, 0, 0
2, doc, 2, 1
i have key/lookup table in database , table might like:
lookupkey, lookupvalue, lookuptext
with following data lookupkey , lookupvalue primary key (not defined in db):
documentstatus, 0, draft
documentstatus, 1, inreview
documentstatus, 2, final
documentcategory, 0, resume
documentcategory, 1, cover letter
the tables have 2 relationships based on:
documentstatus = lookupvalue , lookupkey = "documentstatus"
and second relationship
documentcategory = lookupvalue , lookupkey = "documentcategory"
can define type of relationship within edmx?
well, if in shoes, change primary key of lookup table compound key on lookupkey , lookupvalue. let's presume unable change structure of database.
yes, can this. essentially, you're going edit ssdl section of edmx in such way same gui designer would've produced if had actual foreign key. 1 way @ association based on real, compound foreign key, , type structure edmx. however, there downside of doing manually. when choose "update model database" in gui designer, replace complete ssdl section every time. wipe out changes. therefore, easier method of doing have separate database, real foreign key compound primary key in lookup value table, use model generation. these separate database same structure runtime database, except defines bit of schema "more correctly." change connect string before update model database, generate model, , change connect string "real" database runtime.
Comments
Post a Comment