如何使用linq获取数据 [英] How to get data using linq
本文介绍了如何使用linq获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的DAL功能。
This is my DAL function.
public IQueryable GetAllCategories()
{
CastroDataContext objDAL = new CastroDataContext();
var varCategories = (from cat in objDAL.Categories
where cat.IsDeleted.Equals(false)
select new
{
CategoryID = this.ToInteger(cat.CategoryID),
CategoryName = this.ToString(cat.CategoryName),
Description = this.ToString(cat.Description),
EvaluationType = this.ToString(cat.EvaluationType),
});
return varCategories;
}
我想知道如何在我的组合框中获取数据。
i我正在尝试这个
and i want to know that how to get the data at my front end in my combobox.
i am trying this
protected void GetCategories()
{
clsCategories DAL = new clsCategories();
IQueryable ds = DAL.GetAllCategories();
CastroDataContext db = new CastroDataContext();
var query = from category in db.Categories select category;
foreach (var row in query)
{
}
}
但是这里是error.plz guaid me
But here are error.plz guaid me
推荐答案
大部分如果不是你的所有问题都在GetCategories()
为什么你在DAL中运行查询然后尝试在GetCategories方法中执行相同操作?
我首先检查以确保ds
变量在运行该例程时其中包含数据(以防万一你怎么办?在该行上放置一个断点) ,跳过它并通过调试器查看返回的内容。
如果返回记录,则可以执行此类操作
Mostly if not ALL of your problem is inGetCategories()
Why are you running a query in your DAL and then trying to do the same in your GetCategories method?
I would firstly check to make sure that theds
variable has data inside of it when you run that routine (just in case you ask how? put a breakpoint on that line, step over it and through the debugger see what gets returned).
If that returns records, you can then do something like this
foreach(var row in ds)
{
//Do something to your data here
//i.e.
int CategoryID = row.CategoryID;
}
hopefully this should give you something to get started with.
这篇关于如何使用linq获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文