【发布时间】:2016-10-12 20:15:18
【问题描述】:
今天我想从 SQL Ce 转到 MongoDB。我下载了驱动程序并在我的 PC 上本地运行服务器。
这是我的实际代码(顺便说一句,我什至不知道将 IMongoCollection 转换为 MongoCollection 是否安全):
using System;
using MongoDB.Driver;
namespace MongoShit
{
class Program
{
class Apple
{
public int price, weight;
public string color;
public Apple()
{
price = 0;
weight = 0;
color = "ayye";
}
}
static protected IMongoClient client;
static protected IMongoDatabase database;
static void Main(string[] args)
{
client = new MongoClient("mongodb://localhost");
database = client.GetDatabase("test");
database.CreateCollection("apples");
var data = new Apple() { price = 100, weight = 500, color = "green" };
MongoCollection<Apple> collection = (MongoCollection<Apple>)database.GetCollection<Apple>("apples");
collection.Insert(data);
var cursor = collection.FindAll();
foreach(Apple a in cursor)
{
Console.WriteLine(string.Format("Apple, P: {0} W: {1} C: {2}", new object[] { a.price, a.weight, a.color }));
}
Console.Read();
}
}
}
但是每当我尝试运行程序时,我都会收到以下错误: mscorlib.dll 中出现“System.IO.FileNotFoundException”类型的未处理异常
其他信息:无法加载文件或程序集“System.Runtime.InteropServices.RuntimeInformation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”或其依赖项之一。系统找不到指定的文件。
发生了什么事? :S
【问题讨论】: