EF Core中的联盟不适用于两个列表

发布于 2025-01-29 12:09:00 字数 267 浏览 4 评论 0 原文

EF Core中的联盟不适用于两个列表。我有错误, “方法'System.linq.tolist'的这种超载当前不支持。”加入两个列表时。

p.List1
.Select(q => new Dto1
{
     Id= q.Id,
     Name= q.Name
}).ToList()
.Union(List2.Select(obj => new Dto1
{
     Id= q.Id,
     Name= q.Name
}).ToList()

Union in EF Core is not working for two lists. I am getting the error,
"this overload of the method 'system.linq.tolist' is currently not supported." when joining two lists.

p.List1
.Select(q => new Dto1
{
     Id= q.Id,
     Name= q.Name
}).ToList()
.Union(List2.Select(obj => new Dto1
{
     Id= q.Id,
     Name= q.Name
}).ToList()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

紙鸢 2025-02-05 12:09:00

您必须将联合结果分配到您的列表或创建另一个列表并分配给

        var result = p.List1
        .Select(q => new Dto1
        {
            Id = q.Id,
            Name = q.Name
        }).ToList();

        result = result.Union(List2.Select(q => new Dto1
        {
            Id = q.Id,
            Name = q.Name
        }).ToList()).ToList();

有关Linq Union,Intersect,Intersect和Difints 在这里学习

You must assign Union result to your List or Create another one List and assign to it

        var result = p.List1
        .Select(q => new Dto1
        {
            Id = q.Id,
            Name = q.Name
        }).ToList();

        result = result.Union(List2.Select(q => new Dto1
        {
            Id = q.Id,
            Name = q.Name
        }).ToList()).ToList();

for more about Linq Union, Intersect, Intersect and Distinct learn here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文