如何创建结果LinQ的列表 [英] How do I create a list of the result LinQ

查看:57
本文介绍了如何创建结果LinQ的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello People,



我已经制作了一些代码,可以导出我们数据库的所有公司名称。

我想创建一个列表,每个结果都是列表中的一个对象。



有人能帮帮我吗?



我做的这段代码,但我没有弄错。



见下面的代码:







Hello People,

I have made a little code that export all company names of our DB.
I want to create one list that each result is an object in the list.

Could someone help me?

I made this code but I don't get what is wrong.

see code below:



public class Company
    {

        public IEnumerable<Company> CompanyN(int Cname)
        {
            myDB tdc = new myDb();
            var Result= tdc.ExecuteQuery<Company>(@"SELECT TOP (10) [t0].[Id], [t0].[IdAnonymous], [t0].[Name], [t0].[Address1], [t0].[Address2], [t0].[PostalCode], [t0].[City], [t0].[Country], [t0].[Phone], [t0].[Fax], [t0].[Email], [t0].[Web], [t0].[VAT], [t0].[Agreement], [t0].[AgreementEndDate], [t0].[TradosTM], [t0].[PathRefMaterial], [t0].[PaymentTerms], [t0].[Owner], [t0].[CreationDate], [t0].[PriceListName], [t0].[Currency], [t0].[IsActive], [t0].[LogoBlob]FROM [CompanyMain] AS [t0]");
            return Result.ToList();
            foreach (var c in Result)
            {
                Console.WriteLine(c);
            }

        }







有人能帮帮我吗?



我收到此错误:

检测到无法访问的代码。



谢谢提前完成。




Could someone help me?

I get this error:
Unreachable code detected.

Thank you in advance.

推荐答案

在迭代列表之前退出函数。尝试把

You are exiting from function before iterating the list. Try to put
return Result.ToList();



作为函数的最后一个语句。


as last statement of the function.

public class Company
{

    public IEnumerable<Company> CompanyN(int Cname)
    {
        myDB tdc = new myDb();
        var Result= tdc.ExecuteQuery<Company>(@"SELECT TOP (10) [t0].[Id], [t0].[IdAnonymous], [t0].[Name], [t0].[Address1], [t0].[Address2], [t0].[PostalCode], [t0].[City], [t0].[Country], [t0].[Phone], [t0].[Fax], [t0].[Email], [t0].[Web], [t0].[VAT], [t0].[Agreement], [t0].[AgreementEndDate], [t0].[TradosTM], [t0].[PathRefMaterial], [t0].[PaymentTerms], [t0].[Owner], [t0].[CreationDate], [t0].[PriceListName], [t0].[Currency], [t0].[IsActive], [t0].[LogoBlob]FROM [CompanyMain] AS [t0]");
        
        foreach (var c in Result)
        {
            Console.WriteLine(c);
        }
        return Result.ToList(); 
    }


这篇关于如何创建结果LinQ的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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