gpt4 book ai didi

c# - 如何将 Collection 转换为 IQueryable

转载 作者:太空狗 更新时间:2023-10-30 00:34:37 29 4
gpt4 key购买 nike

我正在尝试设置最小起订量,但我需要创建一个伪造的 IQueryable。我制作了一个 Collection,但我不知道如何将其转换为 IQueryable。

Collection<DetailDataEntity> DetailDataEntityCollection = 
new Collection<DetailDataEntity>();

DetailDataEntity DetailDataEntity = new DetailDataEntity();
DetailDataEntity.FeedTypeID = 1;
DetailDataEntityCollection.Add(DetailDataEntity);


_mockRepository.Setup(x => x.GetDetail(It.IsAny<Int32>(),
It.IsAny<Enum.FeedTypeEnum.FeedType>()))
.Returns(DetailDataEntityCollection);

最佳答案

只需对您的集合调用 AsQueryable

_mockRepository.Setup(x => x.GetDetail(It.IsAny<Int32>(), 
It.IsAny<Enum.FeedTypeEnum.FeedType>()))
.Returns(DetailDataEntityCollection.AsQueryable());

关于c# - 如何将 Collection<x> 转换为 IQueryable<x>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7120392/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com