Using aliases in anonymous types causes LINQ query to return NULL values

243 views
Skip to first unread message

Vlad Novgorodov

unread,
Oct 28, 2011, 10:16:59 AM10/28/11
to ravendb
Hi,

I'm using RavenDB 472. When my LINQ query uses aliases in the
anonymous type ("Name", "Address" in the example below) the query
returns correct number of records but the aliased fields are empty. If
I don't use aliases everything works fine.

var documentStore = new DocumentStore() { Url =
"http://localhost:8080" };
documentStore.Initialize();

using (var session =
documentStore.OpenSession("TestDB"))
{
var results =
session.Query<CompanyView>().Select(x => new
{
Name = x.CompanyName,
Address = x.CompanyAddress
}).ToArray();
}

Itamar Syn-Hershko

unread,
Oct 29, 2011, 1:41:37 PM10/29/11
to rav...@googlegroups.com
Thanks, I've added a failing test and we will have a look at that soon

Oren Eini (Ayende Rahien)

unread,
Nov 1, 2011, 6:10:24 AM11/1/11
to rav...@googlegroups.com
Fixed in the next build

Vlad Novgorodov

unread,
Nov 1, 2011, 2:07:07 PM11/1/11
to ravendb
Thanks!

On Nov 1, 12:10 pm, "Oren Eini (Ayende Rahien)" <aye...@ayende.com>
wrote:
> Fixed in the next build
>
> On Sat, Oct 29, 2011 at 1:41 PM, Itamar Syn-Hershko <
>
>
>
>
>
>
>
> ita...@hibernatingrhinos.com> wrote:
> > Thanks, I've added a failing test and we will have a look at that soon
>

Vlad Novgorodov

unread,
Dec 26, 2011, 7:43:54 AM12/26/11
to ravendb
I've just checked build 573 - yes, it's fixed. But the same problem
rises if I use predefined type instead of anonymous one:

Select(x => new MyType

Oren Eini (Ayende Rahien)

unread,
Dec 26, 2011, 7:45:31 AM12/26/11
to rav...@googlegroups.com
Can you show a full failing test?

Vlad Novgorodov

unread,
Dec 26, 2011, 11:56:19 AM12/26/11
to ravendb
public class SampleDocument
{
public Guid DocId;
public string Name;
}

public class ProjectedDocument
{
public Guid MyDocId;
public string MyName;
}

public void Test()
{
Guid docId = Guid.NewGuid();
_session.Store(new SampleDocument { DocId = docId, Name =
"Doc1" });
_session.SaveChanges();

var result = _session.Query<SampleDocument>()
.Select(x => new ProjectedDocument
{
MyDocId = x.DocId,
MyName = x.Name
})
.First();

System.Diagnostics.Debug.Assert(result.MyDocId !=
Guid.Empty);
System.Diagnostics.Debug.Assert(!
string.IsNullOrEmpty(result.MyName));
}

Oren Eini (Ayende Rahien)

unread,
Dec 27, 2011, 3:40:04 AM12/27/11
to rav...@googlegroups.com
Thanks, this will be fixed in the next build
Reply all
Reply to author
Forward
0 new messages