Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Breeze Sharp - Expand not working with lambda expression

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

like image 204
ProxyTech Avatar asked Nov 18 '14 12:11

ProxyTech


2 Answers

Try like followings

query = query.ToList().Expand(val => val.Dealers);
like image 58
Mahedee Avatar answered Nov 16 '22 14:11

Mahedee


query = query.Include(val => val.Dealers);
like image 37
Elliot Naylor Avatar answered Nov 16 '22 13:11

Elliot Naylor