Michael
unread,Apr 11, 2011, 2:32:42 PM4/11/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to mongodb-user
Hi all,
I'm trying to use the MongoDB CSharpDriver with a POCO holding a
composite key.
But I've got problems using the MongoCollection.Save method...
This is a sample :
namespace MongodbTest
{
class Id
{
public int AccountId { get; set; }
public int Index { get; set; }
}
class Foo
{
[BsonId]
public Id Id;
public string name;
}
class Program
{
static void Main(string[] args)
{
MongoServer server = MongoServer.Create("mongodb://
localhost");
MongoDatabase test = server.GetDatabase("test");
MongoCollection<Foo> foos =
test.GetCollection<Foo>("foos");
Foo newFoo = new Foo { Id = new Id { AccountId = 1, Index
= 1 }, name = "foo1-1" };
// will throw an ArgumentException ".NET type
MongodbTest.Id cannot be mapped to a BsonValue"
foos.Save(newFoo);
// will work with no pb
foos.Update(QueryWrapper.Create(new { _id = newFoo.Id }),
UpdateWrapper.Create<Foo>(newFoo), UpdateFlags.Upsert);
// will work with no pb
Foo foo = foos.FindOne(QueryWrapper.Create(new { _id =
newFoo.Id }));
}
}
}
Thank you,
Michael