Explicit construction of entity type
-
Sunday, October 18, 2009 11:00 AM
I have a DataModel that contains a Hour table and a HourService that contains the pregenerated CRUD methods.
I have modified the GetHours() to this:
public IQueryable GetHours()
{
return from hours in this.Context.Hours
select new Hour()
{
HourID = hours.HourID
};
}The reason why I construct a new Hour and set the properties manually is that I have some custom properties defined in a shared.cs file that I'm going to set manually.
This code compiles fine but in runtime I get the following error:
"Explicit construction of entity type 'DataModel.Hour' in query is not allowed."
Any help is appreciated!
All Replies
-
Sunday, October 18, 2009 11:17 AM
I have tried to instantiate and return an other type of entity that is not part of the DataModel - that works just fine.
Could it be a Linq to Sql problem?
-
Sunday, October 18, 2009 11:18 AM
Hi,
There are discusstion about exception like that at post.
-
Friday, March 12, 2010 8:59 AMTry using func<T,TResult>:
h => new Hours { HourID= h.HourID };
Func<Hours, Hours> make =
return from h in this.Context.Hours
select make(h);
Hope this can help
Jeremy
-
Friday, February 24, 2012 9:38 AM



