I'm new to .NET framework. I am working on a 3 tier ASP.NET application that uses Linq to SQL for data access. I don't know how to return a Linq to SQL result to the UI layer. ON the BLL, I have a code like this:
dataContex db = new dataContex;
var data = db.DB_TBL;
I obviously cannot return var
type. How do I return the query result to the UI layer?
You can return db.DBL_TBL which will return IQueriable. For example,
public IQueriable<DB_TBL> GetTable()
{
dataContex db = new dataContex;
return db.DB_TBL
}
You can also return IEnumerable or List as well. See example below which returns List.
public List<DB_TBL> GetTable()
{
dataContex db = new dataContex;
return db.DB_TBL.ToList();
}
Then in your UI, use the return types.
Actually binding to a control like a repeater still happens server side. To send your data directly to UI take a look on JSON. It is a better way dealing with data transport (you do transport only for data as opposed to data+markup as it happens by using server side controls).
And since you are new I would recommend working with data on UI, simply it gives you a lot of flexibility. And you keep the code clean.
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.