Hello all,
In my ASP.NETMVC application have 4 model classes.
ProductModel
- public class ProductModel
- {
- public int ProductID { get; set; }
- public string ProductName { get; set; }
- public int SupplierID { get; set; }
- public int CategoryID { get; set; }
- }
- public class CategoriesModel
- {
- public int CategoryID { get; set; }
- public string CategoryName { get; set; }
- public string Description { get; set; }
- }
- public class SuppliersModel
- {
- public int SupplierID { get; set; }
- public string CompanyName { get; set; }
- public string ContactName { get; set; }
- public string ContactTitle { get; set; }
- public string Phone { get; set; }
- public string City { get; set; }
- public string Country { get; set; }
- }
- public class Products_Categories_SuppliersModel
- {
- public string ProductName { get; set; }
- public string ContactName { get; set; }
- public string ContactTitle { get; set; }
- public string CompanyName { get; set; }
- public string Phone { get; set; }
- public string City { get; set; }
- public string Country { get; set; }
- public string CategoryName { get; set; }
- public string Description { get; set; }
- }
I have data in List, List, List. Used LINQ to join all three Lists<>.
- public List
GetProduct_Category_SupplierData() - {
- try
- {
- List
prodData = GetProductsData().ToList(); - List
categData = GetCategoriesData().ToList(); - List
supplData = GetSuppliersData(); - var DBData = (from p in prodData
- join c in categData
- on p.CategoryID equals c.CategoryID
- join s in supplData on p.SupplierID equals s.SupplierID
- select new
- {
- p.ProductName,
- c.CategoryName,
- c.Description,
- s.ContactName,
- s.ContactTitle,
- s.CompanyName,
- s.Phone,
- s.City,
- s.Country
- });
- return DBData.ToList();
- }
- catch (Exception) { return null; }
- finally {}
- }
But Line # 24 throws error - Cannot implicitly convert type 'System.Collections.Generic.List' to 'System.Collections.Generic.List'.
What's the mistake in above code.? I have created Products_Categories_SuppliersModel class such that return data should be of 'Products_Categories_SuppliersModel' type.
Please suggest me to figure out my mistakes & help me code in a better way.
Thanks in advance.
Abhilash J APosted Jun 25, 2017, 1:49 AM
Products_Categories_SuppliersModelin your select.L APosted Jun 25, 2017, 7:24 PM
Mobeen RashidPosted Jun 25, 2017, 1:43 AM
L APosted Jun 24, 2017, 11:48 PM
Rajkiran SwainPosted Jun 24, 2017, 12:40 PM