c# - 将 IMongoCollection 转换为 ObservableCollection
问题描述
无法转换IMongoCollection<MatchDocument>
为ObservableCollection<MatchDocument>
MongoClient client = new MongoClient();
var DB = client.GetDatabase("MTR");
var Collection = DB.GetCollection<MatchDocument>("MATCHES");
App.Profiles = new ObservableCollection<MatchDocument>(Collection);
解决方案
您可以使用Collection.Find<MatchDocument>(query).ToListAsync()
:
MongoClient client = new MongoClient();
var DB = client.GetDatabase("MTR");
var Collection = DB.GetCollection<MatchDocument>("MATCHES");
Task<IList<MatchDocument>> doc = await Collection.Find<MatchDocument>(query).ToListAsync();
ObservableCollection<MatchDocument> Profiles = new ObservableCollection<MatchDocument>(doc.Result);
参考:无法从 'MongoDB.Driver.IMongoCollection<>' 转换为 'System.Collections.Generic.IEnumerable<>'
推荐阅读
- docker - Docker 检查等效 w/buildkit/buildctl
- java - BridgeException: null:-1 将 SVG 转码为 BufferedImage 并引用不存在的掩码
- javascript - 凭据无效时向用户显示的错误消息
- google-sheets - Google 表格 - 计算给定日期之间 Importrange 数据的唯一值
- html - row-sm 和 row-cols-sm-n(其中 n<12) 有什么作用?我见过 col-sm-n 的用法(其中 n<12),但我不知道 row-sm 的用法
- apache-nifi - 使用 NiFi 将 json 内容放入字段中的 Jolt 转换
- browser - 了解从 Web 启动的应用程序
- javascript - 如何使用 javascript 获取每个请求
- javascript - JavaScript NodeJS 如何将流/承诺与异步函数一起使用?
- google-cloud-platform - 关于 Google Cloud Translate API 的欧盟区域端点的说明