Created
September 13, 2012 10:09
-
-
Save NathanGloyn/3713359 to your computer and use it in GitHub Desktop.
Raven query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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); | |
} |
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
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