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
99●5●5●9