DataPortal.Fetch failed (Only parameterless constructors and initializers are supported in LINQ to Entities.)

DataPortal.Fetch failed (Only parameterless constructors and initializers are supported in LINQ to Entities.)

Old forum URL: forums.lhotka.net/forums/t/5585.aspx


koen@skn.be posted on Tuesday, October 14, 2008

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;

}

}

RockfordLhotka replied on Tuesday, October 14, 2008

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.

kyle.l.watson@gmail.com replied on Thursday, January 22, 2009



Julie Lerman Blog

I am not sure if this is the reason why you're particular error is occuring but when I was playing with L2E I was able to fetch my projectInfo objects by  using the example in the link :

Throws error:
var data = from p in ctx.ObjectContext.Project
                select new ProjectInfo( p.id, p.Name);

this.addRange(data); //Throws Parameterless Contructors exception




Doesn' throw error:

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