asp.net mvc 3 - How to want to move my DAL to separate project in my MVC3 solution? -


i have mvc 3 application uses dal (ado.net) communicates set of tsql stored procedures? want add new mvc project current solution. need have dal in separate project 2 mvc project ("monitor" , "audit") can share.

here's current dal (which sits in folder of "monitor" mvc project) code below. issue have signature ienumerable located in monitor.models , ienumerable located in audit.models. need make dal generic avoid needing make references models in dal?

ex:  **//is bad practice?**     using monitor.models;     using adit.models;    namespace monitor.dal {     public class questiondal     {         static ilog log = log4net.logmanager.getlogger(typeof(questiondal));         private string _connectionstring = webconfigurationmanager.connectionstrings["nexgencontext"].tostring();          public ienumerable<agencyterm> searchagencies(string ori, string name)         {             log.debug("executing: searchagencies(string ori, string name)");             list<agencyterm> agencies = new list<agencyterm>();             using (var conn = new sqlconnection(_connectionstring))             {                 var com = new sqlcommand();                 com.connection = conn;                 com.commandtype = commandtype.storedprocedure;                 string term = "ori";                  if (!string.isnullorempty(ori))                  {                    term = "ori";                    com.parameters.add(new sqlparameter                    {                         parametername = "@ori",                         value = ori                     });                 }                 if (!string.isnullorempty(name))                 {                     term = "legal_name";                     com.parameters.add(new sqlparameter                     {                         parametername = "@name",                         value = name                     });                 }                 com.commandtext = "review_get_agency_list";                 var adapt = new sqldataadapter();                 adapt.selectcommand = com;                 var dataset = new dataset();                 adapt.fill(dataset);                  agencies = (from c in dataset.tables[0].asenumerable()                             select new agencyterm()                                          {                                              label = c[term].tostring(),                                              id = c["agency_id"].tostring()                                          }).tolist<agencyterm>();                  return agencies;             }          }          public ienumerable<user> getusers()         {             log.debug("executing: getusers()");             list<user> users = new list<user>();             using (var conn = new sqlconnection(_connectionstring))             {                 var com = new sqlcommand();                 com.connection = conn;                 com.commandtype = commandtype.storedprocedure;                 com.commandtext = "review_get_users";                 var adapt = new sqldataadapter();                 adapt.selectcommand = com;                 var dataset = new dataset();                 adapt.fill(dataset);                  users = (from c in dataset.tables[0].asenumerable()                             select new user()                             {                                 user_id = convert.toint32(c["user_id"]),                                 department = c["department"].tostring(),                                 enabled = convert.toboolean(c["enabled"]),                                 email = c["email"].tostring(),                                 user_first_name = c["user_first_name"].tostring(),                                 user_last_name = c["user_last_name"].tostring(),                                 location = c["location"].tostring(),                                 user_name = c["user_name"].tostring()                             }).tolist<user>();                  return users;             }          }  

you have 2 possibilities:

  • either move model separate library , reference mvc project , dal
  • make dal generic , push values inside. don't see easy way here though since have lot of information in dal

i go first option. extract models different project , reuse library in both dal , mvc-projects


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

What is the difference between data design and data model(ERD) -

ios - Can NSManagedObject conform to NSCoding -