Skip to content

One-to-many properties not loading correctly #5429

@leontyr

Description

@leontyr

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions