TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Andile Choko
NA
53
54.3k
Anonymous Types error: Retrieving data from different columns using linq
Sep 16 2012 7:26 PM
Hi mindcrackers,
Here's my code:
public List<DAL.Assessment> search_by_id(Int64 id)
{
DAL.PVA_DBMSEntities objEntity = new DAL.PVA_DBMSEntities();
var getdata = (from sub in objEntity.Subjects
from skul in objEntity.Schools
from leaner in objEntity.Learners
from ass in objEntity.Assessments
where (ass.Learner_Id == leaner.Learner_Id)
&& (ass.Learner_Id == id) && (ass.Subject_Id == sub.Subject__Id)
select new
{
leaner.Learner_Id,
sub.Description,
ass.Assessment_type,
ass.Mark,
});
return (List<DAL.Assessment>)getdata;
}
Server Error in '/' Application.
Unable to cast object of type 'System.Data.Objects.ObjectQuery`1[<>f__AnonymousType3`4[System.Int32,System.String,System.String,System.Decimal]]' to type 'System.Collections.Generic.List`1[PVA.DAL.Assessment]'.
Description:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details:
System.InvalidCastException: Unable to cast object of type 'System.Data.Objects.ObjectQuery`1[<>f__AnonymousType3`4[System.Int32,System.String,System.String,System.Decimal]]' to type 'System.Collections.Generic.List`1[PVA.DAL.Assessment]'.
Source Error:
Line 93: }); Line 94:
Line 95: return (List<DAL.Assessment>)getdata;
Line 96: }
Thank You.
Reply
Answers (
1
)
Cannot use the output of LINQ query
How to convert the result of LINQ query to List