如何返回ICollection< object>从linq,使用select new object(){}时 [英] How to return ICollection<object> from linq, when using select new object() {}

查看:48
本文介绍了如何返回ICollection< object>从linq,使用select new object(){}时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在使用下面的linq,但是我真正想要的是返回ICollection<SexyPeopleVM>而不是列表.但是我无法理解语法,而我尝试过的其他替代方法在运行时都失败了.

I have the below linq currently working, but what I would really like is to return an ICollection<SexyPeopleVM> instead of a list. But I can't get my head around the syntax and other alternative I've tried have failed at runtime.

这可能吗?我该如何实现?

var o = from s in sexyPeople
                    select new SexyPeopleVM()
                    {
                        id = s.ID,
                        title = s.Title,
                        views = s.Views,
                        url = s.GetFullyQualifiedURL(),
                        friendlyDate = s.DateCreated.AsShortFriendly()
                    };
            List<SexyPeopleVM> list = o.ToList();
            return list;

推荐答案

List<T>实现ICollection<T>.
您无需执行任何操作.

List<T> implements ICollection<T>.
You don't need to do anything.

这篇关于如何返回ICollection&lt; object&gt;从linq,使用select new object(){}时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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