Entity Framework loads everything in Polygon, but my list LineSegments. What am I missing?
Polygon:
public class Polygon
{
List<LineSegment> _lineSegments = new List<LineSegment>();
public List<LineSegment> LineSegments
{
get { return _lineSegments; }
protected set { _lineSegments = value; }
}
public Point BasePoint { get; protected set; }
public Vector NormalVector { get; protected set; }
public int? DatabaseId { get; set; }
}
Class LineSegment ( Polygonhas a list of them)
public class LineSegment
{
public virtual Distance Magnitude
{
get { return _magnitude; }
set { _magnitude = value; }
}
private Distance _magnitude;
public virtual Point BasePoint
{
get { return _basePoint; }
set { this._basePoint = value; }
}
private Point _basePoint;
public virtual Direction Direction
{
get { return _direction; }
set { _direction = value; }
}
private Direction _direction;
public int? DatabaseId { get; set; }
}
And here is the relationship setting in the model:
modelBuilder.Entity<Polygon>()
.HasMany(polygon => polygon.LineSegments);
So, there is a table for both Polygons and LineSegments, and they are inserted correctly where LineSegment has a link to Polygon. But when I try to restore them using the downloaded download, it does not load the list. I have LineSegment properties listed in include, but it does not work. I think I need to change the relationship setting in the model, but I donβt know how to do it. How can I fix this so that I can eagerly load the LineSegments list when Polygon boots up? Here's the request:
private static List<Expression<Func<Polygon, object>>> polygonRegionNaviationProperties = new List<Expression<Func<Polygon, object>>>()
{
(polygon => polygon.BasePoint),
(polygon => polygon.BasePoint.X),
(polygon => polygon.BasePoint.Y),
(polygon => polygon.BasePoint.Z),
(polygon => polygon.NormalVector),
(polygon => polygon.NormalVector.Direction),
(polygon => polygon.NormalVector.Direction.Phi),
(polygon => polygon.NormalVector.Direction.Theta),
(polygon => polygon.NormalVector.Magnitude),
(polygon => polygon.NormalVector.BasePoint.X),
(polygon => polygon.NormalVector.BasePoint.Y),
(polygon => polygon.NormalVector.BasePoint.Z),
(polygon => polygon.LineSegments),
(polygon => polygon.LineSegments.Select(lineSegment => lineSegment.Direction)),
(polygon => polygon.LineSegments.Select(lineSegment => lineSegment.Direction.Phi)),
(polygon => polygon.LineSegments.Select(lineSegment => lineSegment.Direction.Theta)),
(polygon => polygon.LineSegments.Select(lineSegment => lineSegment.Magnitude)),
(polygon => polygon.LineSegments.Select(lineSegment => lineSegment.BasePoint.X)),
(polygon => polygon.LineSegments.Select(lineSegment => lineSegment.BasePoint.Y)),
(polygon => polygon.LineSegments.Select(lineSegment => lineSegment.BasePoint.Z))
};
public Polygon GetPolygon(int? databaseId)
{
if(databaseId != null)
{
Polygon retrievedPolygon = Query((polygon => polygon.DatabaseId == databaseId), polygonRegionNaviationProperties);
return retrievedPolygon;
}
else
{
return null;
}
}
public override Polygon Query(Expression<Func<Polygon, bool>> match, List<Expression<Func<Polygon, object>>> includes = null)
{
using (var databaseContext = new ClearspanDatabaseContext())
{
databaseContext.Database.Log = Console.Write;
if (includes != null)
{
var dataSet = databaseContext.Set<Polygon>();
Polygon retrievedObject = includes.Aggregate(
dataSet.AsQueryable(),
(current, include) => current.Include(include)
).SingleOrDefault(match);
databaseContext.Entry(retrievedObject).Collection(polygon => polygon.LineSegments).Load();
return retrievedObject;
}
else
{
Polygon retrievedObject = databaseContext.Set<Polygon>().SingleOrDefault(match);
databaseContext.Entry(retrievedObject).Collection(polygon => polygon.LineSegments).Load();
return retrievedObject;
}
}
}
UPDATE
, .
- .
- (
git submodule init git submodule update ) ( , SourceTree) - PostgreSQL script, , . .
- , , InsertAndRetrievePolygon. , List , , .
, , . , , GeometryClassLibrary. ,