Using EntityFramework with a GPConn.Net Connection
A long while ago I wondered if it was possible to take an existing SQLConnection created by GPConn.Net and create an EntityFramework context for it. ย I have finally gotten around to proving that it can work quite nicely.
For clarity, the Connection property in the code below is a SQLConnection object that was created using GPConn.Net. ย This means that my applications can now have the users login with their DynamicsGP username and password. ย We get the convenience of the EntityFramework with security and context of DynamicsGP.
//Creates an EntityFramework context from an EXISTING SqlConnection (From GPConn) MetadataWorkspace workspace = new MetadataWorkspace(new string[]{"res://*/"},new Assembly[]{Assembly.GetExecutingAssembly()}); using (EntityConnection entityConnection = new EntityConnection(workspace, this.Connection)) { using (GPDataClassesDataContext context = new GPDataClassesDataContext(entityConnection)) { //Create new ViewModel and pass context ViewModels.JobCostBurdenSetupViewModel vm = new ViewModels.JobCostBurdenSetupViewModel(context); //Create new Control and pass in viewmodel _control = new BSystem.Payroll.Views.JobCostBurdenSetupUserControl(vm); base.Initialize(); } }














