In my CustomerList i have a factory that gets the correct DAL and this for the acomping database
My business objects can not have any knowledge of the database !!
This application has to run on different databases.
When i execute the application i get the error :
DataPortal.Fetch failed (Only parameterless constructors and initializers are supported in LINQ to Entities.)
How to resolve this ?
protected void DataPortal_Fetch()
{
FetchDAL();
}
private void FetchDAL()
{
RaiseListChangedEvents = false;
IsReadOnly = false;
var DALFactory = new CustomerDALFactory();
using (CustomerDAL dal = DALFactory.CreateCustomersDAL())
{
var data = (IEnumerable<CustomerInfo>) dal.GetDBCustomers();
foreach (CustomerInfo info in data)
{
Add(info);
}
//AddRange(data);
}
IsReadOnly =
true;RaiseListChangedEvents =
true;}
DAL :
public class CustomerEAL : CustomerDAL{
public override object GetDBCustomers(){
var ctx = ObjectContextManager<NaturalEntities>.GetManager("NaturalEntities"); var data = (from p in ctx.ObjectContext.Contact select new CustomerInfo(p.ContactId, p.Naam)); return data;}
}
Are you trying to have EF directly create/load your business objects with data? The current version of EF is not really flexible enough to deal with CSLA objects (not easily anyway). Microsoft says they are working on POCO (plain old CLR objects) support for a future release, and perhaps those enhancements will make EF work with CSLA objects directly.
Also, in CSLA 3.6 there's a new ObjectFactory concept that externalizes data access code entirely out of the business object - no DataPortal_XYZ methods in the object. This feature is something I specifically added in anticipation of these future EF features - but that is almost certainly a better model for what you are trying to do as well.
var data = from p in ctx.ObjectContext.ProjectDoesn' throw error:
select new ProjectInfo( p.id, p.Name);
this.addRange(data); //Throws Parameterless Contructors exception
var data = from p in ctx.ObjectContext.Project
select p;
List<ProjectInfo> mylist = new List<ProjectInfo>();
foreach ( var temp in data)
{
mylist.add( new ProjectInfo(temp.id, temp.Name);
}
this.addRange(mylist);
An extra step is required.
Anyway, I was just messing around with different data access technologies and maybe that will help someone.
Copyright (c) Marimer LLC