querybuilder icon indicating copy to clipboard operation
querybuilder copied to clipboard

.Include does work with the Get<TEntity>

Open brezaie opened this issue 4 years ago • 3 comments

Hi pals, When doing the following query, the NameEntityType is still null:

public class NameEntity {
    public int Id { get; set; }
    public int NameEntityTypeId { get; set; }
    public virtual NameEntityType NameEntityType { get; set; }
}

public class NameEntityType {
    public int Id { get; set; }
    public virtual System.Collections.Generic.ICollection<NameEntity> NameEntities { get; set; }
}


var res = queryFactory.Query("NameEntity")
                .Include("NameEntityType", queryFactory.Query("NameEntityType"), "NameEntityTypeId")
		.Get<NameEntity>();

Could you please let me know about the way to solve the issue?

brezaie avatar Oct 21 '19 18:10 brezaie

@brezaie currently the Include works only with Get<dynamic> overload, this is a known limitation, that will get solved soon. You can for now return the result as IEnumeratble<dynamic> then cast it to the type you want IEnumerable<T>.

ahmad-moussawi avatar Oct 22 '19 10:10 ahmad-moussawi

@ahmad-moussawi Do you have an example how to cast the IEnumerable<dynamic> (which I think is Dictionary<string, object> at runtime) to IEnumerable<T>? The explicit casting or using Cast() from the generic collection will throw InvalidCastException, I also tried Slapper.AutoMapper but it seems like it does not support mapping with private constructors/setters.

jliu212 avatar Nov 03 '20 14:11 jliu212

@ahmad-moussawi Has the work been done to allow for the Include to work with the generic type methods?

CallumWalterWhite avatar Mar 10 '23 09:03 CallumWalterWhite