【发布时间】:2011-02-09 14:24:44
【问题描述】:
我想将匿名类型的对象存储到 db4o 数据库。例如:
// Store an object of anonymous type to the db
var foobar = new {Foo="Ugh", Bar="Oh!"};
using (var db = Db4oEmbedded.OpenFile("db.db40"))
{
db.Store(foobar);
}
我正在使用以下代码来检索对象:
// Retrieve it in a separate program
using (var db = Db4oEmbedded.OpenFile("db.db40"))
{
var query=from dynamic fb in db select fb;
query.Dump();
}
但是,在检索后无法访问对象的属性:转储(在 Linqpad 中)给出:
5IEnumerable<Object> (3 items)
GenericObject
(G) <>f__AnonymousType0`2[[System.String, mscorlib], [System.String, mscorlib]], query_vrfldn
GenericObject
(G) <>f__AnonymousType0`2[[System.String, mscorlib], [System.String, mscorlib]], query_oqabew
GenericObject
(G) <>f__AnonymousType0`2[[System.String, mscorlib], [System.String, mscorlib]], query_cfvuva
db4o 是否支持这个用例?我怎样才能将对象整齐地从数据库中取出?
【问题讨论】:
标签: .net database c#-4.0 anonymous-types