c# - How to ensure certain properties are always populated when returning object from DAL? -


i have question class has property optionlist, nothing list. questions , options stored in diff tables in db.

now there times when need question object without relational properties, properties entities mapping different table in db. in case not need optionlist populated.

but again there times when need optionlist property populated.

the approach thinking of right having 2 different methods.

public question getquestionbyid(int qid)  public question getquestionwitoptions(int qid) 

so if call second metho, ensure optionlist populated in returned question object.

is way achieve such result? alternate ideas , suggestions?

i'd it's pretty method. you're using defined names obvious purpose , function.

the other suggestion can think of create second class:

public class questionextended : question {     public questionextended(ienumerable<option> options) : base()     {         optionlist = new list<option>(options);     }      public list<option> optionlist { get; private set;} } 

so actual class implementation gives obvious meaning what's inside , what's required it.


Comments

Popular posts from this blog

unicode - Are email addresses allowed to contain non-alphanumeric characters? -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

c++ - Convert big endian to little endian when reading from a binary file -