This question is locked. New answers and comments are not allowed.
Hello,
We're migrating our solution to the Telerik OpenAccess ORM. We've got a couple of questions about how the ORM could fit into our current system design. Specifically we're using a 3-layer design (Domain Driven Design), each of our modules has 3 main folders where each layer is located into.
+ Presentation
+ Domain
+ Enums
+ Models
+ Data
So in the Data layer we have static classes that represent our repositories, within each repository we have methods for the basic CRUD operations. What we want to achieve is replace the implementation of the CRUD methods with calls to the ORM Open Access Context.
Here comes our main problem, in the ORM every CRUD operation is done via the OpenAccess Context, however there are three ways in which we can implement that. The problem is mainly with long-lived entities that have to be passed from one WinForm to another (or generally used by some business logic class).
In the below code snippet we've outlined the three ways we can implement the CRUD operations with the ORM.
V1 - the main problem is we're not leaving a reference to the context, what would happen if the GC runs and disposes the context?
V2 - creating a detached copy, this works but we're basically not using the ORM to its full potential and add more code to create detached entities.
V3 - having a global OpenAccess Context that we keep, what happens when you query it multiple times for the same objects (refreshing a list of items for example). With this our main concern is it may eat up resources while trying to keep track of multiple objects that will never get commited to the DB.
We're migrating our solution to the Telerik OpenAccess ORM. We've got a couple of questions about how the ORM could fit into our current system design. Specifically we're using a 3-layer design (Domain Driven Design), each of our modules has 3 main folders where each layer is located into.
+ Presentation
+ Domain
+ Enums
+ Models
+ Data
So in the Data layer we have static classes that represent our repositories, within each repository we have methods for the basic CRUD operations. What we want to achieve is replace the implementation of the CRUD methods with calls to the ORM Open Access Context.
Here comes our main problem, in the ORM every CRUD operation is done via the OpenAccess Context, however there are three ways in which we can implement that. The problem is mainly with long-lived entities that have to be passed from one WinForm to another (or generally used by some business logic class).
In the below code snippet we've outlined the three ways we can implement the CRUD operations with the ORM.
V1 - the main problem is we're not leaving a reference to the context, what would happen if the GC runs and disposes the context?
V2 - creating a detached copy, this works but we're basically not using the ORM to its full potential and add more code to create detached entities.
V3 - having a global OpenAccess Context that we keep, what happens when you query it multiple times for the same objects (refreshing a list of items for example). With this our main concern is it may eat up resources while trying to keep track of multiple objects that will never get commited to the DB.
public
static
class
PatientRepository
{
//Variant 1
public
static
Patient F_GetPatientByID_V1(
uint
patientID)
{
return
new
EntitiesModel().Patients.Where(p => p.PatientID == patientID).FirstOrDefault();
}
//Variant 2
public
static
Patient F_GetPatientByID_V2(
uint
patientID)
{
using
(var dbContext =
new
EntitiesModel())
{
Patient pat = dbContext.Patients.Where(p => p.PatientID == patientID).FirstOrDefault();
return
dbContext.CreateDetachedCopy<Patient>(pat);
}
}
//Variant 3
private
static
EntitiesModel DbContext =
new
EntitiesModel();
public
static
Patient F_GetPatientByID_V3(
uint
patientID)
{
return
DbContext.Patients.Where(p => p.PatientID == patientID).FirstOrDefault();
}
}