-
Notifications
You must be signed in to change notification settings - Fork 3.4k
One-to-many properties not loading correctly #5429
Copy link
Copy link
Closed as not planned
Description
Ok, this is not a request for lazy loading or eager loading. I simply can't load the data I should.
I am using "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-rc2-final"
public class Property
{
public int Id { get; set; }
public int PropertyTypeId { get; set; }
public PropertyType PropertyType { get; set; }
}
public class PropertyType
{
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public int Id { get; set; }
public virtual ICollection<Property> Properties { get; set; }
}
If I do
var properties = from x in _context.Properties
select x;
return properties;
propertyType is null. (Should it not be eager loaded since I didn't use virtual?)
If I do
return properties.Include(p => p.PropertyType);
I get first property with the propertyType. However, within the propertyType, there is an empty properties array which causes an infinite loop for the rest of the properties to show.
The workaround I can do is to add Newtonsoft.Json.ReferenceLoopHandling.Ignore. But this is just a one-to-many relationship. It shouldn't need it, right?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Type
Fields
Give feedbackNo fields configured for issues without a type.