We have a solution which use ADO.NET before. Now we want to use Entity Framework instead of ADO.NET.
Can someone advise if there is a way we switch data access between them without any change of DAL?
Lot of thanks in advance.
You should read Chapter 18 of the Expert 2008 Business Objects book, and probably watch the Core 3.8 video series, because there's an entire video segment devoted to data access. Also read the data access FAQ: http://www.lhotka.net/cslanet/faq/DataFaq.ashx
CSLA supports four data access models (see the FAQ). If you are using models 2-4, and your DAL interface is highly abstract (probably means using DTO objects for data transfer between your business objects and the DAL), then you can switch between DAL implementations very easily. Of course that comes at a cost, in that your DAL implementations are a little more complex than otherwise - but nothing comes for free.
Thanks a lot, Rockford.
In the video 3.8 video 3 you demonstrated how to create an interface DAL factory so that we can switch btw data access technologies easily. The sample you created for one of the BO DAL (TestObject) used a IDataReader as return type of the Fetch method. This won't be applicable for EF as all the results are returned as IEnumerable.
So does it make sense to make the return type to IEnumerable instead, as that would allow the data reader to be return as well? But this means we cannot just dump it into the SafeDataReader, can we?
The problem with IDataReader is that EF doesn't expose data reader objects. Really, IDataReader is an excellent choice if your DAL implementations will be based on ADO.NET itself.
If your DAL implementations are going to be EF based, or will be a mix of EF, ADO.NET and who-knows-what-else, then your DAL interface needs to be more abstract, and should probably use DTOs.
Mix of EF & ADO.NET - This is exactly the direction we are exploring. Basically, we would like to examine the pros and cons of changing the DAL to EF, hence we are changing part of the BOs to fetch via EF but we would like to switch back easily. Existing DAL objects are all using ADO.NET right now and returning the results in the IDataReader type, which is as you mentioned not exposed by the EF.
Copyright (c) Marimer LLC