2

Ho to everybody. Below you can see the partial result of the EF Power Tools reverse engineering made on the database of mine.

public partial class Articoli {        
    public decimal Id_Articolo { get; set; }
    public string Codice { get; set; }
    public virtual ICollection<Udc_Dettaglio> FK_Udc_Dettaglio_Articoli { get; set; }
}

public partial class Udc_Dettaglio {
    public decimal Id_Udc { get; set; }
    public decimal Id_Articolo { get; set; }
    public virtual Articoli FK_Udc_Dettaglio_Articoli { get; set; }
}

public Udc_DettaglioMap() {
    // Primary Key
    this.HasKey(t => new { t.Id_Udc, t.Id_Articolo });

    // Relationships
    this.HasRequired(t => t.FK_Udc_Dettaglio_Articoli)
        .WithMany(t => t.FK_Udc_Dettaglio_Articoli)
        .HasForeignKey(d => d.Id_Articolo);        
}

If, by using breeze, i try to perform this query

breeze.EntityQuery.from("Articoli").expand("FK_Udc_Dettaglio_Articoli")

or this one

breeze.EntityQuery.from("Articoli").select("Codice,FK_Udc_Dettaglio_Articoli")

everything works fine, but if i try with this

breeze.EntityQuery.from("Articoli").select("Codice,FK_Udc_Dettaglio_Articoli.Id_Udc")

it throw an exeption :

Unable to locate property 'Id_Udc' on type 'System.Collections.Generic.ICollection`1[AWM.Models.Udc_Dettaglio]'."

Am I missing something in EF model definition ? i guess not because expand utility is working ...

  • Same issue here. Why provide a breeze example that can not be used. Seems kind of strange. Maybe this will be addressed in an update. – Bernesto Mar 24 '14 at 02:35

1 Answers1

1

I believe you are trying to build a query that EF doesn't support (and that OData query syntax doesn't support either).

Your FK_Udc_Dettaglio_Articoli is a collection navigation property of Articoli. By trying to go after just the Id_Udc property of each element in that collection, you are actually trying to create a projection within a projection ... and EF doesn't support that as far as I know.

To verify, try to construct a LINQ query on the server side that does what you want. Something like

dbContext.Articoli.Select(
    a => new {a.Codice, a.FK_Udc_Dettaglio_Articoli.Select(f => new {f.Id_Udc}));

You'll quickly discover that that query does not compile. You get a message something like "anonymous type projection initializer should be simple name or member access expansion".

Ward
  • 17,793
  • 4
  • 37
  • 53
  • thx, maybe you are right, but what about if i try to apply the any/all clauses [link](http://www.breezejs.com/documentation/query-examples#Where clauses with any/all conditions on related properties) and obtain another error : **Cannot read property 'dataType' of null**.`{Udc_Dettaglio:#AWM.Models} any {{FK_Udc_Dettaglio_Articoli.Id_Udc} gt {2}}` here the clause string, it seems to be correct, but error is raised. – user2961498 Feb 04 '14 at 08:03
  • `{FK_Udc_Dettaglio_Articoli} any {{Id_Udc} gt {3}}` is the correct one. but I anyway get back: **Cannot read property 'isAnonymous' of undefined**. – user2961498 Feb 04 '14 at 18:21
  • I found that 'Cannot read property 'isAnonymous' of undefined' triggered in certain queries due to case sensitivity in the resource name. EntityQuery.from('products') is not the same as EntityQuery.from('Products'). – Bernesto May 12 '14 at 16:37
  • *That is correct*, @Bernesto. Breeze must be case-sensitive when generating URLs because the HTTP spec says that paths in URLs are case-sensitive ([RF 3986: 6.2.2.1](http://tools.ietf.org/html/rfc3986#section-6.2.2)) even if the server happens to treat them as case-insensitive. We have no choice in the matter. Blame the HTTP spec, not us. – Ward May 13 '14 at 19:20