Tech
Forums
Jobs
Books
Events
Videos
Conference
Annual Conference
Bcrypt
Ai Conference
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
1
Reply
Anonymous Types error: Retrieving data from different columns using linq
Ask a question
Ask a question
Upload Source Code:
Select only zip and rar file.
Andile Choko
12y
2.2k
1
Reply
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.
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
Cannot use the output of LINQ query
How to convert the result of LINQ query to List