如何使用Linq!返回函数中的表? [英] How to Return Table in Function With Linq!?

查看:91
本文介绍了如何使用Linq!返回函数中的表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private Table1 Result() 
{
   Table1 t = new Table1();
    var q =
        from k in DataBase.Table1s
       where k.Id>0
        select k;
t = q;//Erorr!! How To Resolve This Section.With Cast Also is Not Resolve

return t;
 }



我有一张桌子.它的名字是Table1
我想使用表1对象返回此查询的结果吗?
但我不知道!!



I have one table.it Name is Table1
I want to Return Result this Query with Table1 Objects?
but I Dont Know!!!

推荐答案

private Table1 Result()
{
Table1 t = new Table1();
t =
DataBase.Table1s.Single(k=>k.Id>0);

}



试试这个:
Hi,
Try this:
private Table1 Result()
{
    // Suppose your DataContext class name is TestDataContex. 
    TestDataContext ctx = new TestDataContext();
    var Query =  from c in ctx.Table1s select c;
    // Now you got a query. Use it as required.
}



请参考了解LINQ(C#) [ [



Refer Understanding LINQ (C#)[^] and Using LINQ to Objects in C#[^].


All the best.
--Amit


这篇关于如何使用Linq!返回函数中的表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆