i upgraded my application .Net Framework version from 3.5 to 4.5.1 and also i changed the targeted version from 3.5 to 4.5.1. my application using Linq to SQL.. in my application i am using Class Library and in class library i need to pass multiple parameters in Generic list...
In Data Access Layer i have method where i am trying to pass a multiple class that generated by Linq to Sql. (tblaccount, vendorCategory)
internal class BasicDataDAO
{
internal List<tblaccount, vendorCategory> GetAllvendor()
{
using (CommonDataContext VendorDC = new CommonDataContext(Settings.ConnectionString))
{
VendorDC.DeferredLoadingEnabled = true;
return (from V in VendorDC.tblaccounts
join C in VendorDC.vendorCategories on V.CatID equals C.Vendor_CatID
where V.Sys_AC_type == 7
select new
{
V.ID,
V.ACCOUNT,
V.field2,
V.contactDetails,
V.Remarks,
V.field3,
V.field1,
V.email,
V.fax,
C.vendor_CategoryName
}).ToList();
}
}
}
here how i am handling this in Business layer
public List<tblaccount, vendorCategory> GetAllVendors()
{
BasicDataDAO dao = new BasicDataDAO();
return dao.GetAllvendor();
}
but i am getting this error in both Data and Business Layers
Using the generic type System.Collections.Generic.List requires 1 type arguments
how to achieve this task, in which you can pass multiple classes generated by linq in Generic List?
although i have upgraded .Net Framework from 3.5 to 4.5.1 but still i am not able to reference the System.Tuple class in my Class Library
You cannot declare list with two type arguments.
You can use Tuple<T1, T2>
instead: List<Tuple<tblaccount, vendorCategory>>
or create your own class with 2 properties.
But looking at your code, it looks like you're trying to return anonymous type instance as method result. That's not what anonymous types are for:
You cannot declare a field, a property, an event, or the return type of a method as having an anonymous type . Similarly, you cannot declare a formal parameter of a method, property, constructor, or indexer as having an anonymous type. To pass an anonymous type, or a collection that contains anonymous types, as an argument to a method, you can declare the parameter as type object. However, doing this defeats the purpose of strong typing. If you must store query results or pass them outside the method boundary, consider using an ordinary named struct or class instead of an anonymous type .
Follow the guidelines and create your own class to hold results of your query, and declare method as List<MyClass>
.
use iQueryable Class to return an anonymous type
public IQueryable GetAllvendor()
{
CommonDataContext VendorDC = new CommonDataContext(Settings.ConnectionString);
{
VendorDC.DeferredLoadingEnabled = false;
var List = (from V in VendorDC.tblaccounts
join C in VendorDC.vendorCategories on V.CatID equals C.Vendor_CatID
where V.Sys_AC_type == 7
select new
{
V.ID,
V.ACCOUNT,
V.field2,
V.contactDetails,
V.Remarks,
V.field3,
V.field1,
V.email,
V.fax,
C.vendor_CategoryName
});
return List;
}
}
and on the calling site
public IQueryable GetAllVendors()
{
BasicDataDAO dao = new BasicDataDAO();
return dao.GetAllvendor();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.