我正在尝试使用 SQL Server 中的值预填充 MongoDB 的 POCO 类中的引用字段。
我尝试设置的 SQL Server 中的值:7EDC170D61A2E111BA4B0050569B0004
在要插入 MongoDB 的 POCO 类中,我有以下内容:
Employee e = new Employee();
e.CarId = ObjectId.Parse("7EDC170D61A2E111BA4B0050569B0004");
..
collection.Insert<Employee>(e);
问题是我试图从 SQL Server 导入 GUID 值,但我不断收到字节数组大小异常或无效的十六进制字符串异常。
有没有办法可以将 ObjectId 属性值设置为 SQL Server 中的现有 GUID 值?
为了更清楚,我有以下 POCO 类:
public class Employee
{
public ObjectId id {get;set;}
public ObjectId Car {get;set;} //this is the one I would like to set manually with a value from SQL Server
}
希望你能帮忙!