I am completely new to Entities (I've taken over another persons project) and therefore I am prolly missing some key facts but I'll try and explain my problem:
I have applicants who has a table with their information like first name etc. And I also have a table with the ASP.NET Users. The tables are linked by the user_id.
I am trying to make the login name a selectable listitem in a dropdown but in order to do so I need to join the two tables. I have written the following code:
var container = new ModelContainer();
var manager = new ApplicantDBManager();
IEnumerable<Business.Entities.EF.Applicant> applicantQuery;
if (txtSearch.Text.Equals(string.Empty))
{
applicantQuery = container.Applicants;
}
else
{
var ids = manager.ApplicantSearchForIDs(ddlSearch.SelectedValue, txtSearch.Text, chkIncludeInactive.Checked);
applicantQuery = (from a in container.Applicants
join u in container.Users on a.user_id equals u.user_id
where ids.Contains(a.user_id)
select new
{
user_id = a.user_id,
first_name = a.first_name,
last_name = a.last_name,
login_name = u.login_name,
date_of_birth = a.date_of_birth,
kot_cpr = a.kot_cpr,
address = a.address,
email = a.email,
telephone_number = a.telephone_number,
citizenship = a.citizenship
});
}
I am getting an error like "Cannot implicitly convert type System.Linq.Iqueryable to System.Collections.Generic.IEnumerable" and it seems not to matter how I try and fix it (I've tried adding .ToList().AsQueryable(), First() and such with no luck). I think it has something to do with the Applicant entity?
This is the problem:
select new
{
...
}
That's creating an instance of an anonymous type. How do you expect that to create a Business.Entities.EF.Applicant
object?
You may well just need to change your code to:
select new Business.Entities.EF.Applicant
{
...
}
See more on this question at Stackoverflow