asp.net - Application independent of database schema -


i have asp.net application uses entity framework interact database.

in new version working on now, need separate application database can used variety of databases have similar data different schemas. (able used new clients)

so far approach, feels wrong

  • i have objects data entity model generated clients database
  • i custom wrote objects system use
  • i wrote interface outlines of data operations return custom objects
  • i wrote implementation of interface takes client's objects entity framework connected database, , loads fields want custom objects.

this feels wrong have 2 sets of similar objects.

example, here salesorders clients database, , dump data custom job object:

public list<job> getjobs() {      list<job> jobs = new list<job>();      using (var context = new tbdientities.tbdientities())     {         //get future events not cancelled         list<salesorder> salesorders = context.salesorders             .where(c => c.eventconfirmation != "cancelled" && c.functiondate >= datetime.now)             .tolist<salesorder>();          jobs.addrange(from order in salesorders                         let datetime = order.functionstarttime                         datetime != null                         select new job                         {                             description = order.functiontype,                             starttime = (datetime)datetime,                             id = order.salesorderref_txnid.tostring(),                             shiftgroups = new list<shiftgroup>(),                             status = order.eventconfirmation,                             shiftcount = (int)context.bss_shiftlistview                                 .count(c => c.salesorderref_txnid == order.salesorderref_txnid),                             confirmedshifts = (int)context.bss_shiftlistview                                 .count(c => c.salesorderref_txnid == order.salesorderref_txnid && c.confirmed != null),                             client = new client { name = order.customerref_fullname }                         });     }      return jobs; } 

so creating new context, getting collection of salesorders (the table name in clients database), taking the data salesorders , creating new job objects (the ones wrote application interact with) , returning job objects.

this feels wrong have 2 lists of similar objects (salesorders , jobs), , have write crud operations each object rather using entity framework.

example, have page can add new shifts. shifts table different client client, , changes make need update clients table. how write code can use shifts, can have entity framework swapped out schemas new clients? need things shifts in collection can use databind asp:listview.

what smartest way of doing this? how use entity framework independent of customer schema project can reused many databases?

your 2 similar objects performing 2 different roles architectural layers , not redundant. you're working domain models (salesorders), data transfer objects, , view models (jobs). might end 3 sets of objects.

a tool automapper takes out of pain of tedious object-to-object mapping.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -