DbReference Troubles

21 views
Skip to first unread message

Muntedhar Alhakim

unread,
Jul 19, 2011, 8:28:56 AM7/19/11
to NoRM mongodb
Hi All,

Im having trouble with DbReference's, as outlined below:

I have 2 classes, one of which is called Project (which has nothing important), and one is called LogEntry which has a DbReference to Project.

I have tried doing the following as a LINQ Query:

.Where(x => x.Project == new DbReference<Project>("9a3b4304383b618017000000"))

The Project Id is a totally valid ID that I have pulled out of the database, but the above LINQ query returns nothing,

Do you have an idea? I havn't been able to find a solution online for this,

Thanks!

Monty

Andrew Theken

unread,
Jul 19, 2011, 8:34:25 AM7/19/11
to Muntedhar Alhakim, NoRM mongodb
Please post the class definition for "LogEntry"

//Andrew Theken



--
You received this message because you are subscribed to the Google Groups "NoRM mongodb" group.
To post to this group, send email to norm-m...@googlegroups.com.
To unsubscribe from this group, send email to norm-mongodb...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/norm-mongodb?hl=en.

Muntedhar Alhakim

unread,
Jul 19, 2011, 8:40:09 AM7/19/11
to Andrew Theken, NoRM mongodb
In its simplest form:

    public abstract class Entity
    {
        public ObjectId Id { get; set; }
    }
    public class Project : Entity
    {
        public string Name { get; set; }
    }
    public class LogEntry : Entity
    {
        public string Name { get; set; }
        public DbReference<Project> ParentProject { get; set; }

Muntedhar Alhakim

unread,
Jul 19, 2011, 12:10:01 PM7/19/11
to Andrew Theken, NoRM mongodb
Any ideas?

zinark

unread,
Aug 28, 2011, 1:13:16 PM8/28/11
to NoRM mongodb
Did you try this?

.Where(x => x.Project.Id.Equals (new
ObjectId("9a3b4304383b618017000000"))

Muntedhar Alhakim

unread,
Sep 18, 2011, 3:46:32 PM9/18/11
to NoRM mongodb
Tried that, I get the error message of "The method 'Equals' is not supported"

Also tried .Where(x=> x.Project.Id == new ObjectId("9a3b4304383b618017000000"))

and

.Where(x=> x.Project.Id.Value == new ObjectId("9a3b4304383b618017000000").Value)

Which dosent work.

Any more ideas?

Muntedhar Alhakim

unread,
Sep 19, 2011, 3:42:34 PM9/19/11
to NoRM mongodb
I think I have found the problem,

After debugging, the mongo query it generates looks something like:

(this.User.Id == "9a3b4304383b618017000000")

Whereas it needs to be:

(this.User.$id == "9a3b4304383b618017000000")

If anyone can have a look at supplying a patch, it would be greatly
appreciated, where I am currently looking is inside
MongoQueryTranslater.GetDeepAlias, or thereabouts.

Muntedhar Alhakim

unread,
Sep 19, 2011, 3:59:31 PM9/19/11
to NoRM mongodb
This is a dirty dirty hack, but it works, for now.

MongoQueryTranslator.cs, line 272 should read:

string result = string.Join(".", fixedName.Select(x => x.Replace("|
Ind", "")).ToArray());

Paste this underneath:

if
(m.Member.DeclaringType.FullName.StartsWith("Norm.BSON.DbTypes.DbReference"))
{
result = result.Replace("Id", "$id");
}

And it'll prove my point...or at least thats what I think!

Monty
Reply all
Reply to author
Forward
Message has been deleted
0 new messages