c# - Entity Framework generic model design required as an alternative to numerous lookup tables -
i starting on new asp.net mvc project, using entity framework 5 codefirst. application developed going use number of different lookup tables, simple attributes can assigned product (in case, gun)
e.g.
- item condition (poor, average, good, excellent etc.)
- gun orientation (left-handed, right-handed, ambidextrous etc.)
there 10+ of these 'categorisation/attribute' tables.
in addition there need 'make' , 'model' also. these 2 related (in make can have many different models).
finally, few of categorisation tables need relate 1 another. example, 'makes' produce types of gun ('guntypes' lookup table), , gun mechanisms ('gunmechanisms' lookup table) relevant gun types.
initially had designed application model class each of these entities, implementing necessary relationships handle above requirements. however, because elements need re-used non-gun versions of application, i've been asked rid of each of these elements/classes/tables , instead, use more generic approach along lines of having 'category' , 'term' entity.
for example, went below...
public class category { // category be, example, 'gun condition', 'gun orientation', 'make' etc. public int id { get; set;} public string name { get; set;} // category have number of terms associated it. public virtual icollection<term> terms { get; set; } } public class term { // term be, example, 'excellent condition', 'good condition', 'left-handed', 'right-handed' etc. public int id { get; set;} public string name { get; set;} // term belongs category. public virtual category category { get; set; } } public class gun { // edited brevity. public int id { get; set;} public string descrip { get; set;} // of terms (what properties), e.g. 1 term in collection 'excellent condition' category 'gun condition'. 2nd term might 'left-handed' category 'gun orientation', , on. public virtual icollection<term> terms { get; set;} } however, mentioned above, need able deal with:
a) items 'make' & 'model', related 1 another;
b) 'many-to-many' style scenario, 'make' produce 'guntype's, , 'guntype' relevant 'gunmechanism's (e.g. air rifle (gun type) have both 'break barrel' & 'pre-charged' gun mechanism).
i struggling implementation of model design, has been put forward firm requirement.
Comments
Post a Comment