I've just completed watching the 4 video in the CSLA Core video series. We currently are utilizing the standard DataPortal_XYZ methods to retrieve our data but want to move to utilize a separate DAL (i.e. DataAccess.SQL and DataAccess.DB2).
Has anyone utilize this option or is the general consensus to use the ObjectFactory the way to go. We plan on utilizing EF if that changes the decision any way.
Additionally, are there any examples available in constructing this DAL project with DB access (SQLExpress) available? I’m a little hung up on utilizing the connection manager with the DAL project but passing back the DataReader back to the BO to populate the fields.
I found the answer to my second question and corrected my issue with the DAL. I had missed the DpRepos project included with the Core videos. My mistake.
I would still like to know (or get a consensus) on my first question though, taking into consideration EF.
Object Factory vs. DP with DAL
The thing about creating a pluggable DAL is that you need to define the contract for the DAL in a way that is independent of any specific DAL implementation.
IDataReader is one way to do this, because it is an interface-driven scheme.
Data transfer objects (DTOs) are another way to do this, because the DTOs are a consistent type regardless of the DAL implementation - but this incurs extra overhead (typically an extra data copy operation).
EF is hard, because it works on concrete types that are (by default) not polymorphic across different EF models. If you want to directly use EF types, you'll need to make them polymorphic by using partial classes to have them implement a set of interfaces that are consistent for all entities across your different DAL implementations. This can be done, but requires defining and working with a lot of interface types (one for each entity type).
But in the end, this is the key: you must have an implementation-neutral contract for the DAL, so your DP_XYZ or object factory methods can interact with this contract at all times, regardless of which concrete DAL implementation is being invoked.
Thanks for the extra insight Rocky. Definitely something we'll have to consider in implementing a plugable DAL with EF.
Copyright (c) Marimer LLC