Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Is there mongodb C# driver support System.Dynamic.DynamicObject in .NET 4?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  9 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
huy hoang le  
View profile  
 More options Apr 19 2012, 1:52 am
From: huy hoang le <lehuyhoang...@gmail.com>
Date: Wed, 18 Apr 2012 22:52:49 -0700 (PDT)
Local: Thurs, Apr 19 2012 1:52 am
Subject: Is there mongodb C# driver support System.Dynamic.DynamicObject in .NET 4?
Hi,

Im working on a project that use .NET Razor and mongodb. I would like
to do something like this:

@{
        var feeds = DP.Database.GetCollection("feeds").FindAll();

}

                <ul>
                        @foreach (dynamic feed in feeds)
                        {
                                <li>@feed.message - @feed.from.name</li>
                        }
                </ul>

However, the current mongodb C# driver FindAll() return
List<BsonDocument> which does not support dynamic object. Anybody know
a .NET 4 dynamic supported mongodb C# driver?

Thanks a lot


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nat  
View profile  
 More options Apr 19 2012, 2:12 am
From: "Nat" <nat.lu...@gmail.com>
Date: Thu, 19 Apr 2012 06:12:18 +0000
Local: Thurs, Apr 19 2012 2:12 am
Subject: Re: [mongodb-user] Is there mongodb C# driver support System.Dynamic.DynamicObject in .NET 4?
Take a peek at http://blog.abodit.com/2011/09/dynamic-persistence-with-mongodb-look-.... It should give you a good starting point.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
huy hoang le  
View profile  
 More options Apr 19 2012, 2:52 am
From: huy hoang le <lehuyhoang...@gmail.com>
Date: Wed, 18 Apr 2012 23:52:22 -0700 (PDT)
Local: Thurs, Apr 19 2012 2:52 am
Subject: Re: [mongodb-user] Is there mongodb C# driver support System.Dynamic.DynamicObject in .NET 4?

Thanks Nat, seem like official mongo c# driver doesnt support .NET 4


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
huy hoang le  
View profile  
 More options Apr 19 2012, 2:57 am
From: huy hoang le <lehuyhoang...@gmail.com>
Date: Wed, 18 Apr 2012 23:57:31 -0700 (PDT)
Local: Thurs, Apr 19 2012 2:57 am
Subject: Re: Is there mongodb C# driver support System.Dynamic.DynamicObject in .NET 4?
 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
craiggwilson  
View profile  
 More options Apr 19 2012, 10:29 am
From: craiggwilson <craiggwil...@gmail.com>
Date: Thu, 19 Apr 2012 07:29:30 -0700 (PDT)
Local: Thurs, Apr 19 2012 10:29 am
Subject: Re: Is there mongodb C# driver support System.Dynamic.DynamicObject in .NET 4?

Currently, there is no support for dynamic in the MongoDB driver. This is
because it is based on .NET 3.5. However, since a .NET 4.0 assembly can
reference a .NET 3.5 assembly, it is possible for you to write a
IBsonSerializationProvider and an IBsonSerializer in .NET 4.0 to support
dynamics.

We, 10gen, are looking at doing this in the future. I have spiked some
support athttps://github.com/craiggwilson/mongo-csharp-driver/tree/dynamic if
you want to take a look. There are most definitely bugs, but it shows that
it is possible.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
huy hoang le  
View profile  
 More options Apr 20 2012, 12:44 am
From: huy hoang le <lehuyhoang...@gmail.com>
Date: Thu, 19 Apr 2012 21:44:35 -0700 (PDT)
Local: Fri, Apr 20 2012 12:44 am
Subject: Re: Is there mongodb C# driver support System.Dynamic.DynamicObject in .NET 4?

Thanks Craigg, i just found a way to do it and it work!

Add BsonValue to inherit DynamicObject

public abstract class BsonValue : DynamicObject, IComparable<BsonValue>,
IConvertible, IEquatable<BsonValue>

and then add these methods to BsonDocument to implement dynamic support:

        public override bool TryDeleteMember(DeleteMemberBinder binder)
        {
            if (binder == null)
                throw new ArgumentNullException("binder");
            if (Contains(binder.Name))
            {
                Remove(binder.Name);
                return true;
            }
            return false;
        }

        public override bool TryGetMember(GetMemberBinder binder, out
object result)
        {
            BsonValue value;
            if (TryGetValue(binder.Name, out value))
            {
                result = value;
                return true;
            }
            result = null;
            return true;
        }

        public override bool TrySetMember(SetMemberBinder binder, object
value)
        {
            if (binder == null)
                throw new ArgumentNullException("binder");
            Set(binder.Name, BsonValue.Create(value));
            return true;
        }

        public override IEnumerable<string> GetDynamicMemberNames()
        {
            return _indexes.Keys;
        }

Cheers!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
craiggwilson  
View profile  
 More options Apr 20 2012, 8:19 am
From: craiggwilson <craiggwil...@gmail.com>
Date: Fri, 20 Apr 2012 05:19:48 -0700 (PDT)
Local: Fri, Apr 20 2012 8:19 am
Subject: Re: Is there mongodb C# driver support System.Dynamic.DynamicObject in .NET 4?

Yes, that would work.  However, we cannot do this as it would mean changing
our minimum supported framework from 3.5 to 4.0.  If you look at how I did
it in the link I posted above, you'll find that it is fairly similar with
the exception that I cannot use DynamicObject and instead have to drop
lower down the stack because I'm already inheriting from BsonValue.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
huy hoang le  
View profile  
 More options Apr 20 2012, 3:26 pm
From: huy hoang le <lehuyhoang...@gmail.com>
Date: Fri, 20 Apr 2012 12:26:09 -0700 (PDT)
Local: Fri, Apr 20 2012 3:26 pm
Subject: Re: Is there mongodb C# driver support System.Dynamic.DynamicObject in .NET 4?

I see, thanks Craig. I think you guys should release a separate version for
.NET 4


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
nilay  
View profile  
 More options May 15 2012, 1:13 am
From: nilay <nilay.par...@ergosum.in>
Date: Mon, 14 May 2012 22:13:15 -0700 (PDT)
Local: Tues, May 15 2012 1:13 am
Subject: Re: Is there mongodb C# driver support System.Dynamic.DynamicObject in .NET 4?

Theoretically, it is supporting dynamic type. However, (practice) dynamic
type itself conflict with BSON de-serialization,

i.e.
    public class TestClass2<T>
    {
        public MongoDB.Bson.ObjectId Id { get; set; }
        public T data { get; set; }
    }

1. Inserting with TestClass2<int> instance typed as dynamic c# variable, it
will smoothly insert into mongodb as well as retrieve.

2. Now when you try to insert TestClass2<string> dynamic type, save will
work but won't retrieve because of type mismatch and will fail.
Exception message: "An error occurred while deserializing the data property
of class LearningPad.TestClass2`1[[System.Int32, mscorlib, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089]]: Input string was not in
a correct format." @MongoConnection.cs Line 442

3. Only overcome is to use distinguish collections for each possible
generic type (by writing some custom function that evaluate collection name
runtime) but that is impracticable as you can't query them at once.  

4. I use object wrapper (that works fine) with generic promotion of fields
in wrapper to make them queryable and indexable. So far that is the best
solution I'm into.

Any more idea!

Cheers!
N.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »