Hi,

The first query return incorrect results, when asked to select the Name of the type of a Shape to perform an aggregation on it below, I think that Dataobjects isn't behaving correctly (it should either succeed to group by or throw a translation error (because GetType().Name is not in 'SQL Land').

What do you think ?

Many thanks

Code

//Simplified Sample:
Session.Current.Remove(Query.All<ShapesContainer>()) ;
var sc = new ShapesContainer();
sc.Name = "Box";
sc.Shapes.Add(new Square());
sc.Shapes.Add(new Square());
sc.Shapes.Add(new Square());
sc.Shapes.Add(new Triangle());
sc.Shapes.Add(new Triangle());

output.WriteLine("GroupBy GetType() by DO");
sc.Shapes.Select(g=>g.GetType().Name) 
    .GroupBy(g=>g)
    .Select(g=>new{Type = g.Key, Cnt = g.Count()})
    .ToList()
    .ForEach(i=>output.WriteLine(" -- "+i.Type + " # " +i.Cnt));

output.WriteLine("GroupBy TypeId by DO");
sc.Shapes.Select(g=>g.TypeId) 
    .GroupBy(g=>g)
    .Select(g=>new{Type = g.Key, Cnt = g.Count()})
    .ToList()
    .ForEach(i=>output.WriteLine(" -- "+i.Type + " # " +i.Cnt));

output.WriteLine("GroupBy GetType() in memory");
sc.Shapes.Select(g=>g.GetType().Name)
    .ToList()   
    .GroupBy(g=>g)
    .Select(g=>new{Type = g.Key, Cnt = g.Count()})
    .ToList()
    .ForEach(i=>output.WriteLine(" -- "+i.Type + " # " +i.Cnt));
return;

Output

GroupBy GetType() by DO
 -- Square # 1
 -- Square # 1
 -- Square # 1
 -- Triangle # 1
 -- Triangle # 1
GroupBy TypeId by DO
 -- 1341 # 3
 -- 1342 # 2
GroupBy GetType() in memory
 -- Square # 3
 -- Triangle # 2

Model

  [HierarchyRoot]
  public class ShapesContainer:Entity
  {
    [Field]
    public Perimeter Owner { get; private set; }
    [Field, Key]
    public long Id { get; set; }
    [Field]
    public string Name { get; set; }
    [Field, Association(PairTo = "Container", OnOwnerRemove = OnRemoveAction.Cascade, OnTargetRemove = OnRemoveAction.Clear)]
    public EntitySet<IShape> Shapes { get; set; }
  }

  [HierarchyRoot]
  public class Square:Entity, IShape
  {
    [Field, Key]
    public long Id { get; set; }
    [Field]
    public string Complexity { get; set; }
    [Field]
    public int SideLen { get; set; }
    [Field]
    public ShapesContainer Container { get; set; }
  }

  [HierarchyRoot]
  public class Triangle:Entity, IShape
  {
    [Field, Key]
    public long Id { get; set; }
    [Field]
    public string Complexity { get; set; }
    [Field]
    public int SideLen { get; set; }
    [Field]
    public ShapesContainer Container { get; set; }
  }

  [HierarchyRoot]
  public class Rectangle:Entity, IShape
  {
    [Field, Key]
    public long Id { get; set; }
    [Field]
    public string Complexity { get; set; }
    [Field]
    public ShapesContainer Container { get; set; }
    [Field]
    public int Width { get; set; }
    [Field]
    public int Height { get; set; }
  }

  public interface IShape : IEntity
  {
    [Field]
    long Id { get; set; }
    [Field]
    string Complexity { get; set; }
    [Field]
    ShapesContainer Container { get; set; }
  }

Many thanks,

asked May 18 '18 at 09:06

rle's gravatar image

rle
99559


One Answer:

Hello rle

I agree that wrong results in queries is not OK. We will think of what we can do in such situations.

answered Jun 04 '18 at 05:13

Alexey%20Kulakov's gravatar image

Alexey Kulakov
77225

Hi Alexey do you have any update on this ? Many thanks.

(Jan 08 '19 at 03:51) rle rle's gravatar image

Unfortunately no for now

(Jan 18 '19 at 04:12) Alexey Kulakov Alexey%20Kulakov's gravatar image
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

powered by OSQA