如何投射 Collection到 IQueryable
我正在尝试设置最小起订量,但我需要创建一个假的 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);
I am trying to set up a moq, but i am needing to create a fake IQueryable. i made a Collection but i am at a loss of how to cast that to an 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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需对您的集合调用
AsQueryable
即可。Just call
AsQueryable
on your collection.我有一个简单的 ICollection 对象,发现这对我有用:
我必须在 AsQueryable 前面使用 ToList 才能使其工作。
I had a simple ICollection object and found that this worked for me:
I had to use ToList in front of AsQueryable to make it work.