Retrive data from two tables in asp.net mvc using ADO.Net Entity Framework
Posted
by user192972
on Stack Overflow
See other posts from Stack Overflow
or by user192972
Published on 2009-10-20T09:33:32Z
Indexed on
2010/04/06
22:03 UTC
Read the original article
Hit count: 388
Please read my question carefully and reply me.
I have two tables as table1 and table2.
In table1 i have columns as AddressID(Primary Key),Address1,Address2,City
In table2 i have columns as ContactID(Primary Key),AddressID(Foriegn Key),Last Name,First Name.
By using join operation i can retrive data from both the tables.
I created a Model in my MVC Application.I can see both the tables in enitity editor.
In the ViewData folder of my solution explorer i created two class as ContactViewData.cs and SLXRepository.cs
In the ContactViewData.cs i have following code
public IEnumerable<CONTACT> contacts
{
get;
set;
}
In the SLXRepository.cs i have following code
public IEnumerable<CONTACT> GetContacts()
{
var contact =
(
from c in context.CONTACT
join a in context.ADDRESS on c.ADDRESSID equals a.ADDRESSID
select new
{
a.ADDRESS1,
a.ADDRESS2,
a.CITY,
c.FIRSTNAME,
c.LASTNAME
}
);
return contact;
}
I am getting the error in return type Cannot implicitly convert type 'System.Linq.IQueryable' to 'System.Collections.Generic.IEnumerable'. An explicit conversion exists (are you missing a cast?)
© Stack Overflow or respective owner