paulthepaddy
Well-known member
Hi guys, im looking for some help/opinions on the proper way to pass data/objects through various forms.
So im using EF5 but the legacy model, I have a form that will create/load a cars details and then another form to add orders to that car. And here is how i go about it.
My 'Home'(Main) form has db as the entitycontext which is provided by a function so the server address can be changed(good or bad way of doing this?)
So i open my Car form and create or load the car details.
When i open the form im passing the EntityContext (not sure if i should pass the old context or use a new one, I did run into an issue where the objects was already in use by another context) and the Reg of the car
would this be considered the way to do this , and should i be passing around the entitycontext from when the application loads or should i be using new contexts.
or does any of this really matter much.
So im using EF5 but the legacy model, I have a form that will create/load a cars details and then another form to add orders to that car. And here is how i go about it.
My 'Home'(Main) form has db as the entitycontext which is provided by a function so the server address can be changed(good or bad way of doing this?)
VB.NET:
Private db As ImageEntities = GetDB()
Public Function GetDB() As ImageEntities
Dim EntityBuilder As New EntityConnectionStringBuilder
EntityBuilder.Provider = "System.Data.SqlClient"
EntityBuilder.ProviderConnectionString = My.Settings.SQLServer_Address
EntityBuilder.Metadata = "res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl"
Dim EntityConnection As New EntityConnection(EntityBuilder.ToString)
Return New ImageEntities(EntityConnection)
End Function
So i open my Car form and create or load the car details.
VB.NET:
Dim form As New dia_CreateOrder(Car_Reg, db)
Dim Result As DialogResult = form.ShowDialog(Me)
If Result = Windows.Forms.DialogResult.OK Then
Car.Orders.Add(form.Order)
OrdersBindingSource.DataSource = Car.Orders
End If
form.Dispose()
would this be considered the way to do this , and should i be passing around the entitycontext from when the application loads or should i be using new contexts.
or does any of this really matter much.