Breeze Sharp - Expand not working with lambda expression
Asked Answered
D

2

34

When I attempt to expand a navigation property via lambda like so:

query = query.Expand(x => x.Dealers);

My query fails with

This is a failure message

Inner Exception

Inner Exception

Inner Exception Message:

The expression 'x => x.Dealers' is not a valid expression for navigation path. The only supported operations inside the lambda expression body are MemberAccess and TypeAs. The expression must contain at least one MemberAccess and it cannot end with TypeAs.

Yet when I attempt to expand via a string parameter:

query = query.Expand("Dealers");

Everything appears to work correctly.

My "Region" Breeze Client Entity:

public class Region : BaseEntity
{
    public Region();

    public NavigationSet<Dealership> Dealers { get; set; }
    public string Name { get; set; }
    public Region Parent { get; set; }
    public int? ParentId { get; set; }
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    [Key]
    public int RegionId { get; set; }
    public string ShortName { get; set; }
    public RegionType Type { get; set; }
}

My Dealership navigation entity:

public class Dealership : BaseEntity
{
    public Dealership();

    public DateTime ActiveFrom { get; set; }
    public DateTime? ActiveTo { get; set; }
    public Brand Brand { get; set; }
    [ForeignKey("Brand")]
    public int BrandId { get; set; }
    public string DealerCode { get; set; }
    public DealerGroup DealerGroup { get; set; }
    [ForeignKey("DealerGroup")]
    public int? DealerGroupId { get; set; }
    public virtual NavigationSet<DealerIR> DealerIRs { get; set; }
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    [Key]
    public int DealershipId { get; set; }
    public bool IsActive { get; set; }
    public string Line1 { get; set; }
    public string Line2 { get; set; }
    public string Line3 { get; set; }
    public string Line4 { get; set; }
    public string Line5 { get; set; }
    public string Name { get; set; }
    public string PostCode { get; set; }
    public Region Region { get; set; }
    [ForeignKey("Region")]
    public int RegionId { get; set; }
}

My latest attempt was to make the foreign key relationship explicit via the "ForeignKey" data annotation, but the resulting error is still the same.

I'm using breeze sharp v0.6.0.3.

UPDATE 1: It's not the exact same query as above, but same result. Just a screenshot from the Breeze.Sharp source code I've been stepping through. Larger image here

enter image description here

Delgadillo answered 18/11, 2014 at 12:14 Comment(7)
What does the original query look like? i.e. 'query' in your exampleStafford
Hi Jay, original query is: EntityQuery<Region> query = new EntityQuery<Region>(); On a slightly different note, I solved another expand issue I was having due to the fact that the I didn't have my "many" navigation properties set to "NavigationSet" (they were simply just List<>) on my client Breeze entities. I'm in the process of correcting that throughout my object graph. Could it be related?Delgadillo
I've changed all the navigation properties to NavigationSet<>... still no dice. Will update OP with the Breeze.Sharp code piece where it's failing... perhaps it will help..Delgadillo
I'll try to repro this, but I probably won't get to it until next week...Stafford
No prob Jay, I've got a workaround for the time being. While I have you here... is Breeze.Sharp still in active development? Will it be coming out of beta soon? I see that the website hasn't been updated with the v0.6.0.3 release. Are you looking for contributors?Delgadillo
It is still under active dev, but lately we've been focusing on our server story. i.e. new Node and Java servers in addition to our .NET one. but we are beginning to get more interest in Breeze# so I'll probably be getting back to it in a few weeks. At that time, I'll try to author up a doc that describes the tests that need to pass for us to take a pull request. After that I'd love any help :)Stafford
Maybe you could try a workaround by resolving the members name instead of writing a magic string by using this method: nameof. Your usage would be query = query.Expand(x => x.nameof(x=> x.Dealers)); But I haven't tried yet.Sorbose
T
1

Try like followings

query = query.ToList().Expand(val => val.Dealers);
Tractile answered 9/11, 2015 at 10:58 Comment(2)
I don't think the Expand extension method is even available on Linq2Objects?Delgadillo
Please add explanation to your answer.Typescript
H
1
query = query.Include(val => val.Dealers);
Himes answered 7/6, 2016 at 12:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.