[RavenDB] Using property other than "Id" for document key.

Showing 1-10 of 10 messages
[RavenDB] Using property other than "Id" for document key. Wesley Johnson 5/19/10 8:13 PM
I've got an application already built using SQL Express as the backend
and I'm toying around with converting the backend over to Raven DB. My
business/domain objects user a rather redundant way of defining their
keys so my "User" object's key is "UserID". Is it possible to get
Raven to generate it's keys using different names depending on the
object type or at least let me specify the key for each object type
and I'll generate it?

I had a look at FindIdentityProperty, but I'm not exactly sure how to
use it as it doesn't seem to be working the way I attempted. If
FindIdentityProperty is the proper method, an example would be great
and also do I need to set those conventions before initialise() or can
I set them at any time?
Re: [RavenDB] Using property other than "Id" for document key. Ayende Rahien 5/19/10 8:52 PM
Conventions.FindIdProperty = > prop => {
   if(prop.DeclaringType == typeof(User) && prop.Name == "UserId")
        return true;
    return false;
};

Or something like:

Conventions.FindIdProperty = > prop => prop.DeclaringType.Name + "Id"  == prop.Name;
[RavenDB] Re: Using property other than "Id" for document key. Wesley Johnson 5/19/10 9:47 PM
Okay, I tried this:

DocumentStore.Conventions.FindIdentityProperty(prop =>
prop.DeclaringType.Name + "ID" == propertyName);

and I'm getting this error:

Cannot convert lambda expression to type
'System.Reflection.PropertyInfo' because it is not a delegate type.

I trying doing some googling, but I'm really out of my element when it
comes to Linq/Lambda, etc. Thanks for your help so far, any more would
be greatly appreciated!

On May 19, 11:52 pm, Ayende Rahien <aye...@ayende.com> wrote:
> Conventions.FindIdProperty = > prop => {
>    if(prop.DeclaringType == typeof(User) && prop.Name == "UserId")
>         return true;
>     return false;
>
> };
>
> Or something like:
>
> Conventions.FindIdProperty = > prop => prop.DeclaringType.Name + "Id"  ==
> prop.Name;
>
> On Thu, May 20, 2010 at 4:13 AM, Wesley Johnson
> <johnson.wesle...@gmail.com>wrote:
[RavenDB] Re: Using property other than "Id" for document key. Matt Warren 5/19/10 11:29 PM
I think you want to do this instead

  DocumentStore.Conventions.FindIdentityProperty =
      prop => prop.DeclaringType.Name + "ID" == propertyName);

FindPropertyInfo is a setter not a function.
[RavenDB] Re: Using property other than "Id" for document key. Wesley Johnson 5/20/10 7:43 AM
Ah, thanks Matt. I see what I was doing wrong. I'm now having an issue
where the property I defined as an ID is now no longer saved in the
document's content, but I didn't have much time to fiddle around with
that before I had get back to work projects. I'll give it a go again
tonight.

Thanks!
> > > > I set them at any time?- Hide quoted text -
>
> - Show quoted text -
Re: [RavenDB] Re: Using property other than "Id" for document key. Ayende Rahien 5/20/10 8:23 AM
That is intentional, the ID isn't stored with the document, it is _about_ the document.
[RavenDB] Re: Using property other than "Id" for document key. Wesley Johnson 5/20/10 9:10 AM
Thanks, Ayende. I assumed it was intentional, I just wasn't sure how
I'm going to work around it. When I'm querying or loading the document
back out of RavenDB and it's mapping to a instance of my User object,
I need to then populate the aforementioned UserID field with the ID of
the document. I'm hoping that since FindIdentityProperty was set to
that RavenDB knows the UserID property is in indeed my "identity" that
it would map this for me, but I was running into issues with that
field being defaulted in my tests.

Admittedly I hadn't had a chance to really dig, it's possible I was
doing something wrong. I'm a bit rusty with my .NET in general and
LINQ may as well foregin language to me. I'll have a go later this
evening and post back when I'm convinced I can't figure it out on my
own.

Great work on this, btw. I'm enjoying it thus far. :)

On May 20, 11:23 am, Ayende Rahien <aye...@ayende.com> wrote:
> That is intentional, the ID isn't stored with the document, it is _about_
> the document.
>
> On Thu, May 20, 2010 at 3:43 PM, Wesley Johnson
> <johnson.wesle...@gmail.com>wrote:
> > > - Show quoted text -- Hide quoted text -
Re: [RavenDB] Re: Using property other than "Id" for document key. Ayende Rahien 5/20/10 9:20 AM
You shouldn't be able to tell that the ID isn't stored with the document from the client code.
I'll write a test for this.
[RavenDB] Re: Using property other than "Id" for document key. Wesley Johnson 5/20/10 5:59 PM
Everything seems good now. I forgot that I was using an index and
querying for objects based on my "UserID" field before I told RavenDB
it was by actual "Id". Once I fixed the latter part, I forgot to
change the method from retrieving a single object from a query to the
session.load<t> method. Because the "UserID" was no longer part of the
document, but now the "key" - RavenDB wasn't returning any objects and
I was confused.

All is working great now. Thanks for everyone's help!

On May 20, 12:20 pm, Ayende Rahien <aye...@ayende.com> wrote:
> You shouldn't be able to tell that the ID isn't stored with the document
> from the client code.
> I'll write a test for this.
>
> On Thu, May 20, 2010 at 5:10 PM, Wesley Johnson
> <johnson.wesle...@gmail.com>wrote:
Re: [RavenDB] Re: Using property other than "Id" for document key. Ayende Rahien 5/21/10 12:36 AM
Okay, cool