答疑有关ToList

                            
public PermissionDTO[] GetAll()

        {

            using (ZSZDbContext ctx = new ZSZDbContext())

            {

                BaseService<PermissionEntity> bs = new BaseService<PermissionEntity>(ctx);

                return bs.GetAll().ToList().Select(p=>ToDTO(p)).ToArray();

            }

        }

为什么GetAll()之后要ToList(),不能直接Select(p=>ToDTO(p)).ToArray()吗?

答:tolist的作用是把数据从数据库中取到内存中来,如果不tolist的话,你在select中调用ToDTO方法会跑异常的,意思就是ef中不支持使用C#中的方法

原文地址:https://www.cnblogs.com/HuShaoyi/p/8552740.html