Skip to content

Instantly share code, notes, and snippets.

@NathanGloyn
Created September 13, 2012 10:09
Show Gist options
  • Save NathanGloyn/3713359 to your computer and use it in GitHub Desktop.
Save NathanGloyn/3713359 to your computer and use it in GitHub Desktop.
Raven query
[HttpPost]
public ActionResult Create(Create_Album album)
{
if(ModelState.IsValid)
{
var newAlbum = new Album();
newAlbum.Genre = session.Load<Genre>(album.GenreId);
newAlbum.Title = album.Title;
newAlbum.CountSold = album.CountSold;
newAlbum.Price = album.Price;
newAlbum.Artist = session.Query<Artist>("Artists").First(s => s.Id == album.ArtistId);
session.Store(album);
return View("Index");
}
return View(album);
}
@mattwarren
Copy link

Can't you re-write line ##11 as this, so no need for a query? Are Artists separate stand-alone docs or do they only exist inside an Album?

newAlbum.Artist = session.Load(album.ArtistId)

@mattwarren
Copy link

Okay, I've downloaded the latest build and I see the sample data you're using. I get it now, Artists AREN'T separate docs, they only exist inside an Album. In this case line #14 can just be this (just use the Artist data inside the Album that was posted):

newAlbum.Artist = album.Artist

@mattwarren
Copy link

Huh, seems like you've found a bug, I've done a small repo and for a workaround change line #11 to this:

newAlbum.Artist = session.Advanced.LuceneQuery("Artists").Where("Id:" + album.ArtistId).FirstOrDefault();

It seems like Raven is being too clever and changing the name of Id to "__document_Id", which is why you get the error "__document_id" is not indexed, cannot query on fields that are not indexed"?!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment