Wiki Link: [discussion:1601]
Problems with returning strongly typed objects 

Apr 19 2009 at 3:06 PM
Edited Apr 19 2009 at 7:44 PM
I have the following code to return a strongly-typed Test object:

// serializes to JSON and returns strongly typed object for View
var q = (from test in this.Context.Tests
where test.id == id
select new
{
id = test.id,
name = test.name,
Sections = test.Sections.AsEnumerable()
}).First();

return new Test()
{
id = q.id,
name = q.name,
Sections = q.Sections.ToList()
};

I tried return this directly from the query results like so:

// serializes to JSON and returns strongly typed object for View
var q = from test in this.Context.Tests
where test.id == id
select new Test
{
id = test.id,
name = test.name,
Sections = test.Sections.ToList()
};

return q;

However this fails with an runtime error:

'PocoAdapters.SectionAdapter Sections' has no 'set' accessor.

Is this a bug in the framework or am I doing something wrong?

From here:
http://blogs.msdn.com/jkowalski/archive/2008/09/09/persistence-ignorance-poco-adapter-for-entity-framework-v1.aspx

"Adapters are not meant to be seen in any scenarios and users should not be aware of their existence."


Updating...
Page view tracker