FastCrud icon indicating copy to clipboard operation
FastCrud copied to clipboard

Unable to find any child-parent relationship for the child type

Open rsr-maersk opened this issue 3 years ago • 2 comments

Hi Tanks for the coolio package

Unable to find any child-parent relationship for the child type analyzing the navigation property 'Users' on the parent entity.

What to do when i don't want the child items, i just want the parent flat without relationships?

THis doesn't seam to be working: await db.GetAsync(new Foo { Id = id }, options => { options.WithEntityMappingOverride(OrmConfiguration.GetDefaultEntityMapping<Foo>().Clone().RemoveAllRelationships().RemoveProperty(x => x.Bar)); });

The original migration / model is from EF Core many to many.

Unable to find any child-parent relationship for the child type 'Bar' and the parent 'USer' when analyzing the navigation property 'Users' on the parent entity.

even tried with .RemoveParentChildRelationship(x => x.Bar), RemoveParentChildrenRelationship(x => x.Bar), .RemoveChildParentRelationship(x => x.Bar),

rsr-maersk avatar Nov 18 '22 08:11 rsr-maersk

I am getting this error as well, using fluent registration. Here is a simple example to duplicate the issue:

public class Parent {
    public long Key { get; set; }
    public IEnumerable<Child> Children { get; set; }
}

public class Child {
    public long Key { get; set; }
    public long ParentKey { get; set; }
    public Parent Parent { get; set; }
}

public class Config {
    private static void ConfigureParentsAndChildren() {
        OrmConfiguration.GetDefaultEntityMapping<Parent>()
            .SetDialect(SqlDialect.MySql)
            .SetTableName("parents")

            .SetProperty(p => p.Key, p => p
                .SetDatabaseColumnName("parent_id")
                .SetPrimaryKey()
                .SetDatabaseGenerated(DatabaseGeneratedOption.Identity))

            .SetParentChildrenRelationship(                         //<-------- FAILS
                p => p.Children,
                c => c.Parent
            );

        OrmConfiguration.GetDefaultEntityMapping<Child>()
            .SetDialect(SqlDialect.MySql)
            .SetTableName("children")

            .SetProperty(p => p.Key, p => p
                .SetDatabaseColumnName("child_id")
                .SetPrimaryKey()
                .SetDatabaseGenerated(DatabaseGeneratedOption.Identity))

            .SetChildParentRelationship(
                c => c.Parent,
                c => c.ParentKey
            );
    }
}

Is this supposed to work the way I've written it?

slipjig avatar Feb 13 '23 23:02 slipjig

In my example above, if I change it to use .RegisterEntity<T>() instead of .GetDefaultEntityMapping<T>(), it runs.

slipjig avatar Feb 13 '23 23:02 slipjig

In my example above, if I change it to use .RegisterEntity() instead of .GetDefaultEntityMapping(), it runs.

RegisterEntity should be the right way when performing fluent registrations from scratch, as GetDefaultEntityMapping will make inferations that need to be overridden. Let me know if you do encounter any more problems in this area.

MoonStorm avatar Jun 02 '24 08:06 MoonStorm