sách gpt4 ai đã đi

Linq 转换

In lại 作者:行者123 更新时间:2023-12-04 23:10:22 29 4
mua khóa gpt4 Nike

我正在使用以下代码返回 IList:

public IList FindCodesByCountry(string country)
{
var query = from q in session.Linq()
where q.Country == country
orderby q.Code
select new {q.Code};

return (IList) query.ToList();
}

但是我不断收到此错误:

无法转换类型为“System.Collections.Generic.List 1[<>f__AnonymousType0 的对象” 1[System.String]]' 输入'System.Collections.Generic.IList`1[System.String]'。

我应该在这里返回什么?

1 Câu trả lời

只要 q.code 是一个字符串,这应该可以工作:
请注意,它没有创建匿名对象,只是选择了字符串。

    public IList FindCodesByCountry(string country)
{
var query = from q in session.Linq()
where q.Country == country
orderby q.Code
select q.Code;

return query.ToList();
}

关于Linq 转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2103584/

29 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com