Public Class Person
Public Property Id as Integer
Public Property Name As String
End Class
Using db as DocumentSession = store.OpenSession
dim p as New Person With {.Name = "Bobby"}
db.Store(p)
db.SaveChanges()
'at this point p.Id will be the integer value generated by RavenDB
End Using
Using db as DocumentSession = store.OpenSession
' query for entities of type Person with Name = "Bobby"
dim p As Person = db.Query(Of Person).SingleOrDefault(Function(x)
x.Name = "Bobby")
' again, p.Id will be the value generated by RavenDB when the
document was saved.
End Using
<nicolas.roll...@gmail.com> wrote:
> Is it possible, when doing a query for a certain kind of documents, to
> retrieve also the Ids as well as the documents themselves ?
> I did not see how to do so in the documentation.
> I do a plain vanilla query for now:
> use session = store.OpenSession()
> let q = session.Query<MyType>()
On Wednesday, May 2, 2012 1:40:22 PM UTC-4, Bryan Johns wrote:
> Here's an example (VB):
> Public Class Person > Public Property Id as Integer > Public Property Name As String > End Class
> Using db as DocumentSession = store.OpenSession > dim p as New Person With {.Name = "Bobby"} > db.Store(p) > db.SaveChanges() > 'at this point p.Id will be the integer value generated by RavenDB > End Using
> Using db as DocumentSession = store.OpenSession > ' query for entities of type Person with Name = "Bobby" > dim p As Person = db.Query(Of Person).SingleOrDefault(Function(x) > x.Name = "Bobby") > ' again, p.Id will be the value generated by RavenDB when the > document was saved. > End Using
> Do not meddle in the affairs of dragons, for you are crunchy and taste > good with ketchup.
> On Wed, May 2, 2012 at 12:31 PM, Nicolas Spontz > <nicolas.roll...@gmail.com> wrote: > > Is it possible, when doing a query for a certain kind of documents, to > > retrieve also the Ids as well as the documents themselves ?
> > I did not see how to do so in the documentation. > > I do a plain vanilla query for now:
> > use session = store.OpenSession() > > let q = session.Query<MyType>()
Actually, I do not have id inside the document. it is all in the "ravendb id" system from which I can Load any document
So I can perfectly retrieve one particular document using the id, and never added any field that relates to the storage : why pollute my model when ravendb handles it fine ? Now I wanted to mass query them and store them in memory instead of picking them up one by one, hence the need to have access to the id to set up the memory association.
What? You don’t have an Id property on your model classes?
Can you please show us your classes which you store inside raven.
From: ravendb@googlegroups.com [mailto:ravendb@googlegroups.com] On Behalf Of Nicolas Spontz
Sent: Mittwoch, 2. Mai 2012 20:00
To: ravendb@googlegroups.com
Subject: [RavenDB] Re: how to retrieve id's of documents along with the documents themselves in RavenBD
Actually, I do not have id inside the document. it is all in the "ravendb id" system from which I can Load any document
So I can perfectly retrieve one particular document using the id, and never added any field that relates to the storage : why pollute my model when ravendb handles it fine ?
Now I wanted to mass query them and store them in memory instead of picking them up one by one, hence the need to have access to the id to set up the memory association.
On Wednesday, May 2, 2012 7:36:19 PM UTC+2, Daniel Lang wrote:
You should have an Id property on MyType, don't you?
Why? RavenDB auto-generates the integer ID just fine.
session.Load(Of Person)(1) works just fine. Unless you want to use
something other than an integer for your primary key, a string is not
needed.
On Wed, May 2, 2012 at 12:42 PM, Chris Marisic <ch...@marisic.com> wrote:
> It's always better to use string Id with RavenDB.
> On Wednesday, May 2, 2012 1:40:22 PM UTC-4, Bryan Johns wrote:
>> Here's an example (VB):
>> Public Class Person
>> Public Property Id as Integer
>> Public Property Name As String
>> End Class
>> Using db as DocumentSession = store.OpenSession
>> dim p as New Person With {.Name = "Bobby"}
>> db.Store(p)
>> db.SaveChanges()
>> 'at this point p.Id will be the integer value generated by RavenDB
>> End Using
>> Using db as DocumentSession = store.OpenSession
>> ' query for entities of type Person with Name = "Bobby"
>> dim p As Person = db.Query(Of Person).SingleOrDefault(Function(x)
>> x.Name = "Bobby")
>> ' again, p.Id will be the value generated by RavenDB when the
>> document was saved.
>> End Using
>> Do not meddle in the affairs of dragons, for you are crunchy and taste
>> good with ketchup.
>> On Wed, May 2, 2012 at 12:31 PM, Nicolas Spontz
>> <nicolas.roll...@gmail.com> wrote:
>> > Is it possible, when doing a query for a certain kind of documents, to
>> > retrieve also the Ids as well as the documents themselves ?
>> > I did not see how to do so in the documentation.
>> > I do a plain vanilla query for now:
>> > use session = store.OpenSession()
>> > let q = session.Query<MyType>()
Yes, it works. But there are some scenarios where an string is better than an integer because it's more natural to how ravendb works internally. Generally, you want to have your Id like "products/1".
Am Mittwoch, 2. Mai 2012 20:02:46 UTC+2 schrieb Bryan Johns:
> Why? RavenDB auto-generates the integer ID just fine. > session.Load(Of Person)(1) works just fine. Unless you want to use > something other than an integer for your primary key, a string is not > needed.
> Do not meddle in the affairs of dragons, for you are crunchy and taste > good with ketchup.
> On Wed, May 2, 2012 at 12:42 PM, Chris Marisic <ch...@marisic.com> wrote: > > It's always better to use string Id with RavenDB.
> > On Wednesday, May 2, 2012 1:40:22 PM UTC-4, Bryan Johns wrote:
> >> Here's an example (VB):
> >> Public Class Person > >> Public Property Id as Integer > >> Public Property Name As String > >> End Class
> >> Using db as DocumentSession = store.OpenSession > >> dim p as New Person With {.Name = "Bobby"} > >> db.Store(p) > >> db.SaveChanges() > >> 'at this point p.Id will be the integer value generated by RavenDB > >> End Using
> >> Using db as DocumentSession = store.OpenSession > >> ' query for entities of type Person with Name = "Bobby" > >> dim p As Person = db.Query(Of Person).SingleOrDefault(Function(x) > >> x.Name = "Bobby") > >> ' again, p.Id will be the value generated by RavenDB when the > >> document was saved. > >> End Using
> >> Do not meddle in the affairs of dragons, for you are crunchy and taste > >> good with ketchup.
> >> On Wed, May 2, 2012 at 12:31 PM, Nicolas Spontz > >> <nicolas.roll...@gmail.com> wrote: > >> > Is it possible, when doing a query for a certain kind of documents, > to > >> > retrieve also the Ids as well as the documents themselves ?
> >> > I did not see how to do so in the documentation. > >> > I do a plain vanilla query for now:
> >> > use session = store.OpenSession() > >> > let q = session.Query<MyType>()
This is the code part
type Primitive = | PBool of bool
| PChar of char
| PInt of int
| PDouble of double | PString of string
| PDate of DateTime
| PArray of FieldData<Primitive> array
}
On Wednesday, May 2, 2012 8:02:00 PM UTC+2, Daniel Lang wrote:
> What? You don’t have an Id property on your model classes?
> Can you please show us your classes which you store inside raven.
> *From:* ravendb@googlegroups.com [mailto:ravendb@googlegroups.com] *On > Behalf Of *Nicolas Spontz
> *Sent:* Mittwoch, 2. Mai 2012 20:00
> *To:* ravendb@googlegroups.com
> *Subject:* [RavenDB] Re: how to retrieve id's of documents along with the > documents themselves in RavenBD
> Actually, I do not have id inside the document. it is all in the "ravendb > id" system from which I can Load any document
> So I can perfectly retrieve one particular document using the id, and > never added any field that relates to the storage : why pollute my model > when ravendb handles it fine ?
> Now I wanted to mass query them and store them in memory instead of > picking them up one by one, hence the need to have access to the id to set > up the memory association.
> On Wednesday, May 2, 2012 7:36:19 PM UTC+2, Daniel Lang wrote:
> You should have an Id property on MyType, don't you?
On Wednesday, May 2, 2012 8:08:28 PM UTC+2, Nicolas Spontz wrote:
> This is the code part
> type Primitive = | PBool of bool
> | PChar of char
> | PInt of int
> | PDouble of double > | PString of string
> | PDate of DateTime
> | PArray of FieldData<Primitive> array
> On Wednesday, May 2, 2012 8:02:00 PM UTC+2, Daniel Lang wrote:
>> What? You don’t have an Id property on your model classes?
>> Can you please show us your classes which you store inside raven.
>> *From:* ravendb@googlegroups.com [mailto:ravendb@googlegroups.com] *On >> Behalf Of *Nicolas Spontz
>> *Sent:* Mittwoch, 2. Mai 2012 20:00
>> *To:* ravendb@googlegroups.com
>> *Subject:* [RavenDB] Re: how to retrieve id's of documents along with >> the documents themselves in RavenBD
>> Actually, I do not have id inside the document. it is all in the "ravendb >> id" system from which I can Load any document
>> So I can perfectly retrieve one particular document using the id, and >> never added any field that relates to the storage : why pollute my model >> when ravendb handles it fine ?
>> Now I wanted to mass query them and store them in memory instead of >> picking them up one by one, hence the need to have access to the id to set >> up the memory association.
>> On Wednesday, May 2, 2012 7:36:19 PM UTC+2, Daniel Lang wrote:
>> You should have an Id property on MyType, don't you?
On Wednesday, May 2, 2012 8:05:50 PM UTC+2, Daniel Lang wrote:
> Yes, it works. But there are some scenarios where an string is better than > an integer because it's more natural to how ravendb works internally. > Generally, you want to have your Id like "products/1".
> Am Mittwoch, 2. Mai 2012 20:02:46 UTC+2 schrieb Bryan Johns:
>> Why? RavenDB auto-generates the integer ID just fine. >> session.Load(Of Person)(1) works just fine. Unless you want to use >> something other than an integer for your primary key, a string is not >> needed.
>> Do not meddle in the affairs of dragons, for you are crunchy and taste >> good with ketchup.
>> On Wed, May 2, 2012 at 12:42 PM, Chris Marisic <ch...@marisic.com> >> wrote: >> > It's always better to use string Id with RavenDB.
>> > On Wednesday, May 2, 2012 1:40:22 PM UTC-4, Bryan Johns wrote:
>> >> Here's an example (VB):
>> >> Public Class Person >> >> Public Property Id as Integer >> >> Public Property Name As String >> >> End Class
>> >> Using db as DocumentSession = store.OpenSession >> >> dim p as New Person With {.Name = "Bobby"} >> >> db.Store(p) >> >> db.SaveChanges() >> >> 'at this point p.Id will be the integer value generated by RavenDB >> >> End Using
>> >> Using db as DocumentSession = store.OpenSession >> >> ' query for entities of type Person with Name = "Bobby" >> >> dim p As Person = db.Query(Of Person).SingleOrDefault(Function(x) >> >> x.Name = "Bobby") >> >> ' again, p.Id will be the value generated by RavenDB when the >> >> document was saved. >> >> End Using
>> >> Do not meddle in the affairs of dragons, for you are crunchy and taste >> >> good with ketchup.
>> >> On Wed, May 2, 2012 at 12:31 PM, Nicolas Spontz >> >> <nicolas.roll...@gmail.com> wrote: >> >> > Is it possible, when doing a query for a certain kind of documents, >> to >> >> > retrieve also the Ids as well as the documents themselves ?
>> >> > I did not see how to do so in the documentation. >> >> > I do a plain vanilla query for now:
>> >> > use session = store.OpenSession() >> >> > let q = session.Query<MyType>()
You lose features like the ability to query for related documents with Session.Advanced.DatabaseCommands.StartsWith(keyPrefix, skip, take);
The corrallary to this is you lose the ability to create meaningful document keys like "users/1/profile" "users/1/shoppingcart". I found myself needing the hilo key generator almost never anymore because all of my documents generally can have semantic meaning. Some of this relates to your domain.
In my first apps with RavenDB there was nearly zero usages of Load and even to get a single document generally took a Query, in my current app there is almost no usages of anything other than Load unless Query is used to display a list of data.
If you use HiLo extensively and use INT keys, how would you load user/1's profile? You couldn't. You'd be required to do Session.Query<Profile>(x=> x.UserId = "user/1").
On Wednesday, May 2, 2012 2:02:46 PM UTC-4, Bryan Johns wrote:
> Why? RavenDB auto-generates the integer ID just fine. > session.Load(Of Person)(1) works just fine. Unless you want to use > something other than an integer for your primary key, a string is not > needed.
> Do not meddle in the affairs of dragons, for you are crunchy and taste > good with ketchup.
> On Wed, May 2, 2012 at 12:42 PM, Chris Marisic <ch...@marisic.com> wrote: > > It's always better to use string Id with RavenDB.
> > On Wednesday, May 2, 2012 1:40:22 PM UTC-4, Bryan Johns wrote:
> >> Here's an example (VB):
> >> Public Class Person > >> Public Property Id as Integer > >> Public Property Name As String > >> End Class
> >> Using db as DocumentSession = store.OpenSession > >> dim p as New Person With {.Name = "Bobby"} > >> db.Store(p) > >> db.SaveChanges() > >> 'at this point p.Id will be the integer value generated by RavenDB > >> End Using
> >> Using db as DocumentSession = store.OpenSession > >> ' query for entities of type Person with Name = "Bobby" > >> dim p As Person = db.Query(Of Person).SingleOrDefault(Function(x) > >> x.Name = "Bobby") > >> ' again, p.Id will be the value generated by RavenDB when the > >> document was saved. > >> End Using
> >> Do not meddle in the affairs of dragons, for you are crunchy and taste > >> good with ketchup.
> >> On Wed, May 2, 2012 at 12:31 PM, Nicolas Spontz > >> <nicolas.roll...@gmail.com> wrote: > >> > Is it possible, when doing a query for a certain kind of documents, > to > >> > retrieve also the Ids as well as the documents themselves ?
> >> > I did not see how to do so in the documentation. > >> > I do a plain vanilla query for now:
> >> > use session = store.OpenSession() > >> > let q = session.Query<MyType>()
Nicolas, you always need to have an Id property on your classes. They are not part of the documents content, that's true. However, inside your C# or F# classes you will need a property of string or numeric type that is exactly called "Id". This is a convention which you could change if you want to have another name for that. In any case, ravendb will populate that Id property with the documents id after they are retrieved (no matter if you used Load() or Query()).
The reason why Oren isn't populating the Id property before he's saving the object in raven is that RavenDB automatically assigns id then. If your class is called "User", then raven will pluaralize that name and append a HiLo generated number like this: "users/1". If he wanted, he could have specified the id by himself, but there's no reason to do so unless you have objects which have a good natural key that is unique.
Does that make sense to you?
Am Mittwoch, 2. Mai 2012 20:11:37 UTC+2 schrieb Nicolas Spontz:
> The question here is, you can Load using an ID. > But can you query, get the documents back *along with their ids*
> On Wednesday, May 2, 2012 8:05:50 PM UTC+2, Daniel Lang wrote:
>> Yes, it works. But there are some scenarios where an string is better >> than an integer because it's more natural to how ravendb works internally. >> Generally, you want to have your Id like "products/1".
>> Am Mittwoch, 2. Mai 2012 20:02:46 UTC+2 schrieb Bryan Johns:
>>> Why? RavenDB auto-generates the integer ID just fine. >>> session.Load(Of Person)(1) works just fine. Unless you want to use >>> something other than an integer for your primary key, a string is not >>> needed.
>>> Do not meddle in the affairs of dragons, for you are crunchy and taste >>> good with ketchup.
>>> On Wed, May 2, 2012 at 12:42 PM, Chris Marisic <ch...@marisic.com> >>> wrote: >>> > It's always better to use string Id with RavenDB.
>>> > On Wednesday, May 2, 2012 1:40:22 PM UTC-4, Bryan Johns wrote:
>>> >> Here's an example (VB):
>>> >> Public Class Person >>> >> Public Property Id as Integer >>> >> Public Property Name As String >>> >> End Class
>>> >> Using db as DocumentSession = store.OpenSession >>> >> dim p as New Person With {.Name = "Bobby"} >>> >> db.Store(p) >>> >> db.SaveChanges() >>> >> 'at this point p.Id will be the integer value generated by >>> RavenDB >>> >> End Using
>>> >> Using db as DocumentSession = store.OpenSession >>> >> ' query for entities of type Person with Name = "Bobby" >>> >> dim p As Person = db.Query(Of Person).SingleOrDefault(Function(x) >>> >> x.Name = "Bobby") >>> >> ' again, p.Id will be the value generated by RavenDB when the >>> >> document was saved. >>> >> End Using
>>> >> Do not meddle in the affairs of dragons, for you are crunchy and >>> taste >>> >> good with ketchup.
>>> >> On Wed, May 2, 2012 at 12:31 PM, Nicolas Spontz >>> >> <nicolas.roll...@gmail.com> wrote: >>> >> > Is it possible, when doing a query for a certain kind of documents, >>> to >>> >> > retrieve also the Ids as well as the documents themselves ?
>>> >> > I did not see how to do so in the documentation. >>> >> > I do a plain vanilla query for now:
>>> >> > use session = store.OpenSession() >>> >> > let q = session.Query<MyType>()
From: ravendb@googlegroups.com [mailto:ravendb@googlegroups.com] On Behalf Of mvmv
Sent: Mittwoch, 2. Mai 2012 20:30
To: ravendb@googlegroups.com
Subject: Re: [RavenDB] how to retrieve id's of documents along with the documents themselves in RavenBD
a side question, where can I find all the available methods in Session.Advanced.DatabaseCommands and their usage explanation?
I am ready to do whatever tweak, including wrapper or whatnot.
What bugs me, is that there is *already *an *Id* field somewhere in the system (not in my classes), since I can use it when I load a document As in
let r = session.safeLoad<ReferenceValue>(storename)
That is what I do to retrieve my fields. No I want to memoize the whole bunch to gain a few 100's ms. There must be a way to retrieve this already existing information, which, although semantically of no importance on the business layer, can be technically useful for stuff like preloading.
May be there is no way, and may be there is a good reason for that, but I have a hard time seeing it...
On Wednesday, May 2, 2012 8:18:54 PM UTC+2, Daniel Lang wrote:
> Nicolas, you always need to have an Id property on your classes. They are > not part of the documents content, that's true. However, inside your C# or > F# classes you will need a property of string or numeric type that is > exactly called "Id". This is a convention which you could change if you > want to have another name for that. In any case, ravendb will populate that > Id property with the documents id after they are retrieved (no matter if > you used Load() or Query()).
> The reason why Oren isn't populating the Id property before he's saving > the object in raven is that RavenDB automatically assigns id then. If your > class is called "User", then raven will pluaralize that name and append a > HiLo generated number like this: "users/1". If he wanted, he could have > specified the id by himself, but there's no reason to do so unless you have > objects which have a good natural key that is unique.
> Does that make sense to you?
> Am Mittwoch, 2. Mai 2012 20:11:37 UTC+2 schrieb Nicolas Spontz:
>> The question here is, you can Load using an ID. >> But can you query, get the documents back *along with their ids*
>> On Wednesday, May 2, 2012 8:05:50 PM UTC+2, Daniel Lang wrote:
>>> Yes, it works. But there are some scenarios where an string is better >>> than an integer because it's more natural to how ravendb works internally. >>> Generally, you want to have your Id like "products/1".
>>> Am Mittwoch, 2. Mai 2012 20:02:46 UTC+2 schrieb Bryan Johns:
>>>> Why? RavenDB auto-generates the integer ID just fine. >>>> session.Load(Of Person)(1) works just fine. Unless you want to use >>>> something other than an integer for your primary key, a string is not >>>> needed.
>>>> Do not meddle in the affairs of dragons, for you are crunchy and taste >>>> good with ketchup.
>>>> On Wed, May 2, 2012 at 12:42 PM, Chris Marisic <ch...@marisic.com> >>>> wrote: >>>> > It's always better to use string Id with RavenDB.
>>>> > On Wednesday, May 2, 2012 1:40:22 PM UTC-4, Bryan Johns wrote:
>>>> >> Here's an example (VB):
>>>> >> Public Class Person >>>> >> Public Property Id as Integer >>>> >> Public Property Name As String >>>> >> End Class
>>>> >> Using db as DocumentSession = store.OpenSession >>>> >> dim p as New Person With {.Name = "Bobby"} >>>> >> db.Store(p) >>>> >> db.SaveChanges() >>>> >> 'at this point p.Id will be the integer value generated by >>>> RavenDB >>>> >> End Using
>>>> >> Using db as DocumentSession = store.OpenSession >>>> >> ' query for entities of type Person with Name = "Bobby" >>>> >> dim p As Person = db.Query(Of >>>> Person).SingleOrDefault(Function(x) >>>> >> x.Name = "Bobby") >>>> >> ' again, p.Id will be the value generated by RavenDB when the >>>> >> document was saved. >>>> >> End Using
>>>> >> Do not meddle in the affairs of dragons, for you are crunchy and >>>> taste >>>> >> good with ketchup.
>>>> >> On Wed, May 2, 2012 at 12:31 PM, Nicolas Spontz >>>> >> <nicolas.roll...@gmail.com> wrote: >>>> >> > Is it possible, when doing a query for a certain kind of >>>> documents, to >>>> >> > retrieve also the Ids as well as the documents themselves ?
>>>> >> > I did not see how to do so in the documentation. >>>> >> > I do a plain vanilla query for now:
>>>> >> > use session = store.OpenSession() >>>> >> > let q = session.Query<MyType>()
> *From:* ravendb@googlegroups.com [mailto:ravendb@googlegroups.com] *On > Behalf Of *mvmv > *Sent:* Mittwoch, 2. Mai 2012 20:30 > *To:* ravendb@googlegroups.com > *Subject:* Re: [RavenDB] how to retrieve id's of documents along with the > documents themselves in RavenBD
> a side question, where can I find all the available methods > in Session.Advanced.DatabaseCommands and their usage explanation?
From: ravendb@googlegroups.com [mailto:ravendb@googlegroups.com] On Behalf Of Nicolas Spontz
Sent: Mittwoch, 2. Mai 2012 20:33
To: ravendb@googlegroups.com
Subject: Re: [RavenDB] how to retrieve id's of documents along with the documents themselves in RavenBD
I am ready to do whatever tweak, including wrapper or whatnot.
What bugs me, is that there is already an Id field somewhere in the system (not in my classes), since I can use it when I load a document
As in
let r = session.safeLoad<ReferenceValue>(storename)
That is what I do to retrieve my fields. No I want to memoize the whole bunch to gain a few 100's ms.
There must be a way to retrieve this already existing information, which, although semantically of no importance on the business layer, can be technically useful for stuff like preloading.
May be there is no way, and may be there is a good reason for that, but I have a hard time seeing it...
On Wednesday, May 2, 2012 8:18:54 PM UTC+2, Daniel Lang wrote:
Nicolas, you always need to have an Id property on your classes. They are not part of the documents content, that's true. However, inside your C# or F# classes you will need a property of string or numeric type that is exactly called "Id". This is a convention which you could change if you want to have another name for that. In any case, ravendb will populate that Id property with the documents id after they are retrieved (no matter if you used Load() or Query()).
The reason why Oren isn't populating the Id property before he's saving the object in raven is that RavenDB automatically assigns id then. If your class is called "User", then raven will pluaralize that name and append a HiLo generated number like this: "users/1". If he wanted, he could have specified the id by himself, but there's no reason to do so unless you have objects which have a good natural key that is unique.
The question here is, you can Load using an ID.
But can you query, get the documents back along with their ids
On Wednesday, May 2, 2012 8:05:50 PM UTC+2, Daniel Lang wrote:
Yes, it works. But there are some scenarios where an string is better than an integer because it's more natural to how ravendb works internally. Generally, you want to have your Id like "products/1".
Am Mittwoch, 2. Mai 2012 20:02:46 UTC+2 schrieb Bryan Johns:
Why? RavenDB auto-generates the integer ID just fine.
session.Load(Of Person)(1) works just fine. Unless you want to use
something other than an integer for your primary key, a string is not
needed.
On Wed, May 2, 2012 at 12:42 PM, Chris Marisic <ch...@marisic.com<mailto:ch...@marisic.com>> wrote:
> It's always better to use string Id with RavenDB.
> On Wednesday, May 2, 2012 1:40:22 PM UTC-4, Bryan Johns wrote:
>> Here's an example (VB):
>> Public Class Person
>> Public Property Id as Integer
>> Public Property Name As String
>> End Class
>> Using db as DocumentSession = store.OpenSession
>> dim p as New Person With {.Name = "Bobby"}
>> db.Store(p)
>> db.SaveChanges()
>> 'at this point p.Id will be the integer value generated by RavenDB
>> End Using
>> Using db as DocumentSession = store.OpenSession
>> ' query for entities of type Person with Name = "Bobby"
>> dim p As Person = db.Query(Of Person).SingleOrDefault(Function(x)
>> x.Name = "Bobby")
>> ' again, p.Id will be the value generated by RavenDB when the
>> document was saved.
>> End Using
>> Do not meddle in the affairs of dragons, for you are crunchy and taste
>> good with ketchup.
>> On Wed, May 2, 2012 at 12:31 PM, Nicolas Spontz
>> <nicolas.roll...@gmail.com<mailto:nicolas.roll...@gmail.com>> wrote:
>> > Is it possible, when doing a query for a certain kind of documents, to
>> > retrieve also the Ids as well as the documents themselves ?
>> > I did not see how to do so in the documentation.
>> > I do a plain vanilla query for now:
>> > use session = store.OpenSession()
>> > let q = session.Query<MyType>()
On Wednesday, May 2, 2012 2:32:23 PM UTC-4, Nicolas Spontz wrote:
> I am ready to do whatever tweak, including wrapper or whatnot.
> What bugs me, is that there is *already *an *Id* field somewhere in the > system (not in my classes), since I can use it when I load a document > As in
> let r = session.safeLoad<ReferenceValue>(storename)
> That is what I do to retrieve my fields. No I want to memoize the whole > bunch to gain a few 100's ms. > There must be a way to retrieve this already existing information, which, > although semantically of no importance on the business layer, can be > technically useful for stuff like preloading.
> May be there is no way, and may be there is a good reason for that, but I > have a hard time seeing it...
> On Wednesday, May 2, 2012 8:18:54 PM UTC+2, Daniel Lang wrote:
>> Nicolas, you always need to have an Id property on your classes. They are >> not part of the documents content, that's true. However, inside your C# or >> F# classes you will need a property of string or numeric type that is >> exactly called "Id". This is a convention which you could change if you >> want to have another name for that. In any case, ravendb will populate that >> Id property with the documents id after they are retrieved (no matter if >> you used Load() or Query()).
>> The reason why Oren isn't populating the Id property before he's saving >> the object in raven is that RavenDB automatically assigns id then. If your >> class is called "User", then raven will pluaralize that name and append a >> HiLo generated number like this: "users/1". If he wanted, he could have >> specified the id by himself, but there's no reason to do so unless you have >> objects which have a good natural key that is unique.
>> Does that make sense to you?
>> Am Mittwoch, 2. Mai 2012 20:11:37 UTC+2 schrieb Nicolas Spontz:
>>> The question here is, you can Load using an ID. >>> But can you query, get the documents back *along with their ids*
>>> On Wednesday, May 2, 2012 8:05:50 PM UTC+2, Daniel Lang wrote:
>>>> Yes, it works. But there are some scenarios where an string is better >>>> than an integer because it's more natural to how ravendb works internally. >>>> Generally, you want to have your Id like "products/1".
>>>> Am Mittwoch, 2. Mai 2012 20:02:46 UTC+2 schrieb Bryan Johns:
>>>>> Why? RavenDB auto-generates the integer ID just fine. >>>>> session.Load(Of Person)(1) works just fine. Unless you want to use >>>>> something other than an integer for your primary key, a string is not >>>>> needed.
>>>>> Do not meddle in the affairs of dragons, for you are crunchy and taste >>>>> good with ketchup.
>>>>> On Wed, May 2, 2012 at 12:42 PM, Chris Marisic <ch...@marisic.com> >>>>> wrote: >>>>> > It's always better to use string Id with RavenDB.
>>>>> > On Wednesday, May 2, 2012 1:40:22 PM UTC-4, Bryan Johns wrote:
>>>>> >> Here's an example (VB):
>>>>> >> Public Class Person >>>>> >> Public Property Id as Integer >>>>> >> Public Property Name As String >>>>> >> End Class
>>>>> >> Using db as DocumentSession = store.OpenSession >>>>> >> dim p as New Person With {.Name = "Bobby"} >>>>> >> db.Store(p) >>>>> >> db.SaveChanges() >>>>> >> 'at this point p.Id will be the integer value generated by >>>>> RavenDB >>>>> >> End Using
>>>>> >> Using db as DocumentSession = store.OpenSession >>>>> >> ' query for entities of type Person with Name = "Bobby" >>>>> >> dim p As Person = db.Query(Of >>>>> Person).SingleOrDefault(Function(x) >>>>> >> x.Name = "Bobby") >>>>> >> ' again, p.Id will be the value generated by RavenDB when the >>>>> >> document was saved. >>>>> >> End Using
>>>>> >> Do not meddle in the affairs of dragons, for you are crunchy and >>>>> taste >>>>> >> good with ketchup.
>>>>> >> On Wed, May 2, 2012 at 12:31 PM, Nicolas Spontz >>>>> >> <nicolas.roll...@gmail.com> wrote: >>>>> >> > Is it possible, when doing a query for a certain kind of >>>>> documents, to >>>>> >> > retrieve also the Ids as well as the documents themselves ?
>>>>> >> > I did not see how to do so in the documentation. >>>>> >> > I do a plain vanilla query for now:
>>>>> >> > use session = store.OpenSession() >>>>> >> > let q = session.Query<MyType>()
- an Id in the raven db system (aka, what you have in the navigation bar when you edit an Json object in the web interface) - and that you object itself need to have an Id
From what I read in the document you point ot, it say "you CAN create an id property in your object", not you have to.
Which totally makes sense, as you can supply the id while storing stuff, which I do :
session.Store(rv,*storename*)
Storename is then the ravenDB id, but does not exists in my model
> *From:* ravendb@googlegroups.com [mailto:ravendb@googlegroups.com] *On > Behalf Of *Nicolas Spontz
> *Sent:* Mittwoch, 2. Mai 2012 20:33
> *To:* ravendb@googlegroups.com
> *Subject:* Re: [RavenDB] how to retrieve id's of documents along with the > documents themselves in RavenBD
> I am ready to do whatever tweak, including wrapper or whatnot.
> What bugs me, is that there is *already *an *Id* field somewhere in the > system (not in my classes), since I can use it when I load a document
> As in
> let r = session.safeLoad<ReferenceValue>(storename)
> That is what I do to retrieve my fields. No I want to memoize the whole > bunch to gain a few 100's ms.
> There must be a way to retrieve this already existing information, which, > although semantically of no importance on the business layer, can be > technically useful for stuff like preloading.
> May be there is no way, and may be there is a good reason for that, but I > have a hard time seeing it...
> On Wednesday, May 2, 2012 8:18:54 PM UTC+2, Daniel Lang wrote:
> Nicolas, you always need to have an Id property on your classes. They are > not part of the documents content, that's true. However, inside your C# or > F# classes you will need a property of string or numeric type that is > exactly called "Id". This is a convention which you could change if you > want to have another name for that. In any case, ravendb will populate that > Id property with the documents id after they are retrieved (no matter if > you used Load() or Query()).
> The reason why Oren isn't populating the Id property before he's saving > the object in raven is that RavenDB automatically assigns id then. If your > class is called "User", then raven will pluaralize that name and append a > HiLo generated number like this: "users/1". If he wanted, he could have > specified the id by himself, but there's no reason to do so unless you have > objects which have a good natural key that is unique.
> Does that make sense to you?
> Am Mittwoch, 2. Mai 2012 20:11:37 UTC+2 schrieb Nicolas Spontz:
> If you go the exemple from Ayende, he does not store any id either in his > models.
> But can you query, get the documents back *along with their ids*
> On Wednesday, May 2, 2012 8:05:50 PM UTC+2, Daniel Lang wrote:
> Yes, it works. But there are some scenarios where an string is better than > an integer because it's more natural to how ravendb works internally. > Generally, you want to have your Id like "products/1".
> Am Mittwoch, 2. Mai 2012 20:02:46 UTC+2 schrieb Bryan Johns:
> Why? RavenDB auto-generates the integer ID just fine. > session.Load(Of Person)(1) works just fine. Unless you want to use > something other than an integer for your primary key, a string is not > needed.
> Do not meddle in the affairs of dragons, for you are crunchy and taste > good with ketchup.
> On Wed, May 2, 2012 at 12:42 PM, Chris Marisic <ch...@marisic.com> wrote: > > It's always better to use string Id with RavenDB.
> > On Wednesday, May 2, 2012 1:40:22 PM UTC-4, Bryan Johns wrote:
> >> Here's an example (VB):
> >> Public Class Person > >> Public Property Id as Integer > >> Public Property Name As String > >> End Class
> >> Using db as DocumentSession = store.OpenSession > >> dim p as New Person With {.Name = "Bobby"} > >> db.Store(p) > >> db.SaveChanges() > >> 'at this point p.Id will be the integer value generated by RavenDB > >> End Using
> >> Using db as DocumentSession = store.OpenSession > >> ' query for entities of type Person with Name = "Bobby" > >> dim p As Person = db.Query(Of Person).SingleOrDefault(Function(x) > >> x.Name = "Bobby") > >> ' again, p.Id will be the value generated by RavenDB when the > >> document was saved. > >> End Using
> >> Do not meddle in the affairs of dragons, for you are crunchy and taste > >> good with ketchup.
> >> On Wed, May 2, 2012 at 12:31 PM, Nicolas Spontz > >> <nicolas.roll...@gmail.com> wrote: > >> > Is it possible, when doing a query for a certain kind of documents, > to > >> > retrieve also the Ids as well as the documents themselves ?
> >> > I did not see how to do so in the documentation. > >> > I do a plain vanilla query for now:
> >> > use session = store.OpenSession() > >> > let q = session.Query<MyType>()
> *From:* ravendb@googlegroups.com [mailto:ravendb@googlegroups.com] *On > Behalf Of *Nicolas Spontz
> *Sent:* Mittwoch, 2. Mai 2012 20:33
> *To:* ravendb@googlegroups.com
> *Subject:* Re: [RavenDB] how to retrieve id's of documents along with the > documents themselves in RavenBD
> I am ready to do whatever tweak, including wrapper or whatnot.
> What bugs me, is that there is *already *an *Id* field somewhere in the > system (not in my classes), since I can use it when I load a document
> As in
> let r = session.safeLoad<ReferenceValue>(storename)
> That is what I do to retrieve my fields. No I want to memoize the whole > bunch to gain a few 100's ms.
> There must be a way to retrieve this already existing information, which, > although semantically of no importance on the business layer, can be > technically useful for stuff like preloading.
> May be there is no way, and may be there is a good reason for that, but I > have a hard time seeing it...
> On Wednesday, May 2, 2012 8:18:54 PM UTC+2, Daniel Lang wrote:
> Nicolas, you always need to have an Id property on your classes. They are > not part of the documents content, that's true. However, inside your C# or > F# classes you will need a property of string or numeric type that is > exactly called "Id". This is a convention which you could change if you > want to have another name for that. In any case, ravendb will populate that > Id property with the documents id after they are retrieved (no matter if > you used Load() or Query()).
> The reason why Oren isn't populating the Id property before he's saving > the object in raven is that RavenDB automatically assigns id then. If your > class is called "User", then raven will pluaralize that name and append a > HiLo generated number like this: "users/1". If he wanted, he could have > specified the id by himself, but there's no reason to do so unless you have > objects which have a good natural key that is unique.
> Does that make sense to you?
> Am Mittwoch, 2. Mai 2012 20:11:37 UTC+2 schrieb Nicolas Spontz:
> If you go the exemple from Ayende, he does not store any id either in his > models.
> But can you query, get the documents back *along with their ids*
> On Wednesday, May 2, 2012 8:05:50 PM UTC+2, Daniel Lang wrote:
> Yes, it works. But there are some scenarios where an string is better than > an integer because it's more natural to how ravendb works internally. > Generally, you want to have your Id like "products/1".
> Am Mittwoch, 2. Mai 2012 20:02:46 UTC+2 schrieb Bryan Johns:
> Why? RavenDB auto-generates the integer ID just fine. > session.Load(Of Person)(1) works just fine. Unless you want to use > something other than an integer for your primary key, a string is not > needed.
> Do not meddle in the affairs of dragons, for you are crunchy and taste > good with ketchup.
> On Wed, May 2, 2012 at 12:42 PM, Chris Marisic <ch...@marisic.com> wrote: > > It's always better to use string Id with RavenDB.
> > On Wednesday, May 2, 2012 1:40:22 PM UTC-4, Bryan Johns wrote:
> >> Here's an example (VB):
> >> Public Class Person > >> Public Property Id as Integer > >> Public Property Name As String > >> End Class
> >> Using db as DocumentSession = store.OpenSession > >> dim p as New Person With {.Name = "Bobby"} > >> db.Store(p) > >> db.SaveChanges() > >> 'at this point p.Id will be the integer value generated by RavenDB > >> End Using
> >> Using db as DocumentSession = store.OpenSession > >> ' query for entities of type Person with Name = "Bobby" > >> dim p As Person = db.Query(Of Person).SingleOrDefault(Function(x) > >> x.Name = "Bobby") > >> ' again, p.Id will be the value generated by RavenDB when the > >> document was saved. > >> End Using
> >> Do not meddle in the affairs of dragons, for you are crunchy and taste > >> good with ketchup.
> >> On Wed, May 2, 2012 at 12:31 PM, Nicolas Spontz > >> <nicolas.roll...@gmail.com> wrote: > >> > Is it possible, when doing a query for a certain kind of documents, > to > >> > retrieve also the Ids as well as the documents themselves ?
> >> > I did not see how to do so in the documentation. > >> > I do a plain vanilla query for now:
> >> > use session = store.OpenSession() > >> > let q = session.Query<MyType>()
On Wednesday, May 2, 2012 8:37:03 PM UTC+2, Daniel Lang wrote:
> Believe me, there *must* be an Id property on your data classes that you > persist in RavenDB. That’s simply the way it works.
> *From:* ravendb@googlegroups.com [mailto:ravendb@googlegroups.com] *On > Behalf Of *Nicolas Spontz
> *Sent:* Mittwoch, 2. Mai 2012 20:33
> *To:* ravendb@googlegroups.com
> *Subject:* Re: [RavenDB] how to retrieve id's of documents along with the > documents themselves in RavenBD
> I am ready to do whatever tweak, including wrapper or whatnot.
> What bugs me, is that there is *already *an *Id* field somewhere in the > system (not in my classes), since I can use it when I load a document
> As in
> let r = session.safeLoad<ReferenceValue>(storename)
> That is what I do to retrieve my fields. No I want to memoize the whole > bunch to gain a few 100's ms.
> There must be a way to retrieve this already existing information, which, > although semantically of no importance on the business layer, can be > technically useful for stuff like preloading.
> May be there is no way, and may be there is a good reason for that, but I > have a hard time seeing it...
> On Wednesday, May 2, 2012 8:18:54 PM UTC+2, Daniel Lang wrote:
> Nicolas, you always need to have an Id property on your classes. They are > not part of the documents content, that's true. However, inside your C# or > F# classes you will need a property of string or numeric type that is > exactly called "Id". This is a convention which you could change if you > want to have another name for that. In any case, ravendb will populate that > Id property with the documents id after they are retrieved (no matter if > you used Load() or Query()).
> The reason why Oren isn't populating the Id property before he's saving > the object in raven is that RavenDB automatically assigns id then. If your > class is called "User", then raven will pluaralize that name and append a > HiLo generated number like this: "users/1". If he wanted, he could have > specified the id by himself, but there's no reason to do so unless you have > objects which have a good natural key that is unique.
> Does that make sense to you?
> Am Mittwoch, 2. Mai 2012 20:11:37 UTC+2 schrieb Nicolas Spontz:
> If you go the exemple from Ayende, he does not store any id either in his > models.
> But can you query, get the documents back *along with their ids*
> On Wednesday, May 2, 2012 8:05:50 PM UTC+2, Daniel Lang wrote:
> Yes, it works. But there are some scenarios where an string is better than > an integer because it's more natural to how ravendb works internally. > Generally, you want to have your Id like "products/1".
> Am Mittwoch, 2. Mai 2012 20:02:46 UTC+2 schrieb Bryan Johns:
> Why? RavenDB auto-generates the integer ID just fine. > session.Load(Of Person)(1) works just fine. Unless you want to use > something other than an integer for your primary key, a string is not > needed.
> Do not meddle in the affairs of dragons, for you are crunchy and taste > good with ketchup.
> On Wed, May 2, 2012 at 12:42 PM, Chris Marisic <ch...@marisic.com> wrote: > > It's always better to use string Id with RavenDB.
> > On Wednesday, May 2, 2012 1:40:22 PM UTC-4, Bryan Johns wrote:
> >> Here's an example (VB):
> >> Public Class Person > >> Public Property Id as Integer > >> Public Property Name As String > >> End Class
> >> Using db as DocumentSession = store.OpenSession > >> dim p as New Person With {.Name = "Bobby"} > >> db.Store(p) > >> db.SaveChanges() > >> 'at this point p.Id will be the integer value generated by RavenDB > >> End Using
> >> Using db as DocumentSession = store.OpenSession > >> ' query for entities of type Person
You can use this:
var metadata = session.Advanced.GetMetadataFor(yourObject);
var id = metadata["@id"];
However, I would suggest to add an Id property to your class because it’s always easier.
From: ravendb@googlegroups.com [mailto:ravendb@googlegroups.com] On Behalf Of Nicolas Spontz
Sent: Mittwoch, 2. Mai 2012 20:45
To: ravendb@googlegroups.com
Subject: Re: [RavenDB] how to retrieve id's of documents along with the documents themselves in RavenBD
Aren't you confounding the notion of
* an Id in the raven db system (aka, what you have in the navigation bar when you edit an Json object in the web interface)
* and that you object itself need to have an Id
From what I read in the document you point ot, it say "you CAN create an id property in your object", not you have to.
Which totally makes sense, as you can supply the id while storing stuff, which I do :
session.Store(rv,storename)
Storename is then the ravenDB id, but does not exists in my model
On Wednesday, May 2, 2012 8:37:03 PM UTC+2, Daniel Lang wrote:
From: ravendb@googlegroups.com<mailto:ravendb@googlegroups.com> [mailto:ravendb@googlegroups.com<mailto:ravendb@googlegroups.com>] On Behalf Of Nicolas Spontz
Sent: Mittwoch, 2. Mai 2012 20:33
To: ravendb@googlegroups.com<mailto:ravendb@googlegroups.com>
Subject: Re: [RavenDB] how to retrieve id's of documents along with the documents themselves in RavenBD
I am ready to do whatever tweak, including wrapper or whatnot.
What bugs me, is that there is already an Id field somewhere in the system (not in my classes), since I can use it when I load a document
As in
let r = session.safeLoad<ReferenceValue>(storename)
That is what I do to retrieve my fields. No I want to memoize the whole bunch to gain a few 100's ms.
There must be a way to retrieve this already existing information, which, although semantically of no importance on the business layer, can be technically useful for stuff like preloading.
May be there is no way, and may be there is a good reason for that, but I have a hard time seeing it...
On Wednesday, May 2, 2012 8:18:54 PM UTC+2, Daniel Lang wrote:
Nicolas, you always need to have an Id property on your classes. They are not part of the documents content, that's true. However, inside your C# or F# classes you will need a property of string or numeric type that is exactly called "Id". This is a convention which you could change if you want to have another name for that. In any case, ravendb will populate that Id property with the documents id after they are retrieved (no matter if you used Load() or Query()).
The reason why Oren isn't populating the Id property before he's saving the object in raven is that RavenDB automatically assigns id then. If your class is called "User", then raven will pluaralize that name and append a HiLo generated number like this: "users/1". If he wanted, he could have specified the id by himself, but there's no reason to do so unless you have objects which have a good natural key that is unique.
The question here is, you can Load using an ID.
But can you query, get the documents back along with their ids
On Wednesday, May 2, 2012 8:05:50 PM UTC+2, Daniel Lang wrote:
Yes, it works. But there are some scenarios where an string is better than an integer because it's more natural to how ravendb works internally. Generally, you want to have your Id like "products/1".
Am Mittwoch, 2. Mai 2012 20:02:46 UTC+2 schrieb Bryan Johns:
Why? RavenDB auto-generates the integer ID just fine.
session.Load(Of Person)(1) works just fine. Unless you want to use
something other than an integer for your primary key, a string is not
needed.
On Wed, May 2, 2012 at 12:42 PM, Chris Marisic <ch...@marisic.com<mailto:ch...@marisic.com>> wrote:
> It's always better to use string Id with RavenDB.
> On Wednesday, May 2, 2012 1:40:22 PM UTC-4, Bryan Johns wrote:
>> Here's an example (VB):
>> Public Class Person
>> Public Property Id as Integer
>> Public Property Name As String
>> End Class
>> Using db as DocumentSession = store.OpenSession
>> dim p as New Person With {.Name = "Bobby"}
>> db.Store(p)
>> db.SaveChanges()
>> 'at this point p.Id will be the integer value generated by RavenDB
>> End Using
>> Using db as DocumentSession = store.OpenSession
>> ' query for entities of type Person with Name = "Bobby"
>> dim p As Person = db.Query(Of Person).SingleOrDefault(Function(x)
>> x.Name = "Bobby")
>> ' again, p.Id will be the value generated by RavenDB when the
>> document was saved.
>> End Using
>> Do not meddle in the affairs of dragons, for you are crunchy and taste
>> good with ketchup.
>> On Wed, May 2, 2012 at 12:31 PM, Nicolas Spontz
>> <nicolas.roll...@gmail.com<mailto:nicolas.roll...@gmail.com>> wrote:
>> > Is it possible, when doing a query for a certain kind of documents, to
>> > retrieve also the Ids as well as the documents themselves ?
>> > I did not see how to do so in the documentation.
>> > I do a plain vanilla query for now:
>> > use session = store.OpenSession()
>> > let q = session.Query<MyType>()
> The question here is, you can Load using an ID.
> But can you query, get the documents back *along with their ids*
> On Wednesday, May 2, 2012 8:05:50 PM UTC+2, Daniel Lang wrote:
>> Yes, it works. But there are some scenarios where an string is better
>> than an integer because it's more natural to how ravendb works internally.
>> Generally, you want to have your Id like "products/1".
>> Am Mittwoch, 2. Mai 2012 20:02:46 UTC+2 schrieb Bryan Johns:
>>> Why? RavenDB auto-generates the integer ID just fine.
>>> session.Load(Of Person)(1) works just fine. Unless you want to use
>>> something other than an integer for your primary key, a string is not
>>> needed.
>>> Do not meddle in the affairs of dragons, for you are crunchy and taste
>>> good with ketchup.
>>> On Wed, May 2, 2012 at 12:42 PM, Chris Marisic <ch...@marisic.com<javascript:_e({}, 'cvml', 'ch...@marisic.com');>>
>>> wrote:
>>> > It's always better to use string Id with RavenDB.
>>> > On Wednesday, May 2, 2012 1:40:22 PM UTC-4, Bryan Johns wrote:
>>> >> Here's an example (VB):
>>> >> Public Class Person
>>> >> Public Property Id as Integer
>>> >> Public Property Name As String
>>> >> End Class
>>> >> Using db as DocumentSession = store.OpenSession
>>> >> dim p as New Person With {.Name = "Bobby"}
>>> >> db.Store(p)
>>> >> db.SaveChanges()
>>> >> 'at this point p.Id will be the integer value generated by
>>> RavenDB
>>> >> End Using
>>> >> Using db as DocumentSession = store.OpenSession
>>> >> ' query for entities of type Person with Name = "Bobby"
>>> >> dim p As Person = db.Query(Of Person).SingleOrDefault(**Function(x)
>>> >> x.Name = "Bobby")
>>> >> ' again, p.Id will be the value generated by RavenDB when the
>>> >> document was saved.
>>> >> End Using
>>> >> Do not meddle in the affairs of dragons, for you are crunchy and
>>> taste
>>> >> good with ketchup.
>>> >> On Wed, May 2, 2012 at 12:31 PM, Nicolas Spontz
>>> >> <nicolas.roll...@gmail.com <javascript:_e({}, 'cvml',
>>> 'nicolas.roll...@gmail.com');>> wrote:
>>> >> > Is it possible, when doing a query for a certain kind of documents,
>>> to
>>> >> > retrieve also the Ids as well as the documents themselves ?
>>> >> > I did not see how to do so in the documentation.
>>> >> > I do a plain vanilla query for now:
>>> >> > use session = store.OpenSession()
>>> >> > let q = session.Query<MyType>()
On Wednesday, May 2, 2012 8:51:56 PM UTC+2, Daniel Lang wrote:
> Ok,… now I understand what you meant.
> You can use this:
> var metadata = session.Advanced.GetMetadataFor(yourObject);
> var id = metadata["@id"];
> However, I would suggest to add an Id property to your class because it’s > always easier.
> *From:* ravendb@googlegroups.com [mailto:ravendb@googlegroups.com] *On > Behalf Of *Nicolas Spontz
> *Sent:* Mittwoch, 2. Mai 2012 20:45
> *To:* ravendb@googlegroups.com
> *Subject:* Re: [RavenDB] how to retrieve id's of documents along with the > documents themselves in RavenBD
> Aren't you confounding the notion of
> - an Id in the raven db system (aka, what you have in the navigation > bar when you edit an Json object in the web interface) > - and that you object itself need to have an Id
> From what I read in the document you point ot, it say "you CAN create an > id property in your object", not you have to.
> Which totally makes sense, as you can supply the id while storing stuff, > which I do :
> session.Store(rv,*storename*)
> Storename is then the ravenDB id, but does not exists in my model
> On Wednesday, May 2, 2012 8:37:03 PM UTC+2, Daniel Lang wrote:
> Believe me, there *must* be an Id property on your data classes that you > persist in RavenDB. That’s simply the way it works.
> *From:* ravendb@googlegroups.com [mailto:ravendb@googlegroups.com] *On > Behalf Of *Nicolas Spontz
> *Sent:* Mittwoch, 2. Mai 2012 20:33
> *To:* ravendb@googlegroups.com
> *Subject:* Re: [RavenDB] how to retrieve id's of documents along with the > documents themselves in RavenBD
> I am ready to do whatever tweak, including wrapper or whatnot.
> What bugs me, is that there is *already *an *Id* field somewhere in the > system (not in my classes), since I can use it when I load a document
> As in
> let r = session.safeLoad<ReferenceValue>(storename)
> That is what I do to retrieve my fields. No I want to memoize the whole > bunch to gain a few 100's ms.
> There must be a way to retrieve this already existing information, which, > although semantically of no importance on the business layer, can be > technically useful for stuff like preloading.
> May be there is no way, and may be there is a good reason for that, but I > have a hard time seeing it...
> On Wednesday, May 2, 2012 8:18:54 PM UTC+2, Daniel Lang wrote:
> Nicolas, you always need to have an Id property on your classes. They are > not part of the documents content, that's true. However, inside your C# or > F# classes you will need a property of string or numeric type that is > exactly called "Id". This is a convention which you could change if you > want to have another name for that. In any case, ravendb will populate that > Id property with the documents id after they are retrieved (no matter if > you used Load() or Query()).
> The reason why Oren isn't populating the Id property before he's saving > the object in raven is that RavenDB automatically assigns id then. If your > class is called "User", then raven will pluaralize that name and append a > HiLo generated number like this: "users/1". If he wanted, he could have > specified the id by himself, but there's no reason to do so unless you have > objects which have a good natural key that is unique.
> Does that make sense to you?
> Am Mittwoch, 2. Mai 2012 20:11:37 UTC+2 schrieb Nicolas Spontz:
> If you go the exemple from Ayende, he does not store any id either in his > models.
> But can you query, get the documents back *along with their ids*
> On Wednesday, May 2, 2012 8:05:50 PM UTC+2, Daniel Lang wrote:
> Yes, it works. But there are some scenarios where an string is better than > an integer because it's more natural to how ravendb works internally. > Generally, you want to have your Id like "products/1".
> Am Mittwoch, 2. Mai 2012 20:02:46 UTC+2 schrieb Bryan Johns:
> Why? RavenDB auto-generates the integer ID just fine. > session.Load(Of Person)(1) works just fine. Unless you want to use > something other than an integer for your primary key, a string is not > needed.
> Do not meddle in the affairs of dragons, for you are crunchy and taste > good with ketchup.
> On Wed, May 2, 2012 at 12:42 PM, Chris Marisic <ch...@marisic.com> wrote: > > It's always better to use string Id with RavenDB.
> > On Wednesday, May 2, 2012 1:40:22 PM UTC-4, Bryan Johns wrote:
> >> Here's an example (VB):
> >> Public Class Person > >> Public Property Id as Integer > >> Public Property Name As String > >> End Class
> >> Using db as DocumentSession = store.OpenSession > >> dim p as New Person With {.Name = "Bobby"} > >> db.Store(p) > >> db.SaveChanges() > >> 'at this point p.Id will be the integer value generated by RavenDB > >> End Using
> >> Using db as DocumentSession = store.OpenSession > >> ' query for entities of type Person with Name = "Bobby" > >> dim p As Person = db.Query(Of Person).SingleOrDefault(Function(x) > >> x.Name = "Bobby") > >> ' again, p.Id will be the value generated by RavenDB when the > >> document was saved. > >> End Using
> >> Do not meddle in the affairs of dragons, for you are crunchy and taste > >> good with ketchup.
> >> On Wed, May 2, 2012 at 12:31 PM, Nicolas Spontz > >> <nicolas.roll...@gmail.com> wrote: > >> > Is it possible, when doing a query for a certain kind of documents, > to > >> > retrieve also the Ids as well as the documents themselves ?
> >> > I did not see how to do so in the documentation. > >> > I do a plain vanilla query for now:
> >> > use session = store.OpenSession() > >> > let q = session.Query<MyType>()
On Wednesday, May 2, 2012, mvmv wrote:
> a side question, where can I find all the available methods
> in Session.Advanced.**DatabaseCommands and their usage explanation?