wpf - How to dynamically pass connectionstrings in EF5 -


i'm struggling project, converted .net 4.5.

i have functions this:

public shared function load(ijaar integer, ikwartaal integer) list(of loondetail_121)     dim oloondetails new list(of loondetail_121)     try          dim odb new sdwmastersdwdbentities(dbconnections.connstringprisma)          dim dstartdate new date(ijaar, ((ikwartaal - 1) * 3) + 1, 1)          dim denddate new date(ijaar, ((ikwartaal - 1) * 3) + 4, 1)           oloondetails = odb.loondetail_121.where(function(x) x.eindperiode_121 >= dstartdate ,                                               x.eindperiode_121 < denddate).tolist      catch ex exception          throw new exception(getcurrentmethod.name & " " & ex.message)      end try      return oloondetails  end function 

when convert function ef5, errors, since sdcdblonenentities not inherited anymore objectcontext, inherited dbcontext.
before, ef automatically created constructor can pass connection string. easy, because use different connectionstrings, depending on solution configuration (debug/release).
in ef5, constructor doesn't accept connectionstrings anymore. tried create partial class of entity, , create own constructor, can't working:

partial public class sdwmastersdwdbentities     inherits dbcontext      public sub new(sconnstring string)         mybase.new(sconnstring)     end sub end class 

for project, adapted project-file use different app.config files each solution configuration, p.i.t.a maintain , me not clean solution.

so question is: how can use ef5 own personal connectionstrings?

these connection strings way:

 #if debug     friend connstringsdw string = "metadata=res://*/entities.sdwdb.csdl|res://*/entities.sdwdb.ssdl|res://*/entities.sdwdb.msl;provider=system.data.sqlclient;provider connection string='data source=sdwdb01\sdwsql;initial catalog=sdwdb_dev;persist security info=true;user id=usr;password=pwd;multipleactiveresultsets=true;app=entityframework'" #else     friend connstringsdw string = "metadata=res://*/entities.sdwdb.csdl|res://*/entities.sdwdb.ssdl|res://*/entities.sdwdb.msl;provider=system.data.sqlclient;provider connection string='data source=sdwdb01\sdwsql;initial catalog=sdwdb_prod;persist security info=true;user id=usr;password=pwd;multipleactiveresultsets=true;app=entityframework'" #end if 

and error "the entity type sdw_users_master not part of model current context.", when execute function:

public shared function loadall() list(of sdw_users_master)     dim ousers new list(of sdw_users_master)     try         using odb new sdwmaster.sdwmastersdwdbentities(dbconnections.connstringsdw)             ousers = (from tmpusers in odb.sdw_users_master                          select tmpusers).tolist.orderby(function(x) x.login).tolist         end using     catch ex exception         debug.print(ex.message)         throw new exception(getcurrentmethod.name & " " & ex.message)     end try     return ousers end function 

create new partial class same name context, overload constructor. so, if context class named "mycontext", have:

imports system imports system.data.entity imports system.data.entity.infrastructure imports system.data.objects imports system.data.objects.dataclasses imports system.linq  partial public class mycontext   inherits dbcontext    public sub new(connectionstring string)     mybase.new(connectionstring)   end sub  end class 

Comments