Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
rsr-maersk opened this issue Nov 18, 2022 · 3 comments
Closed

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

rsr-maersk opened this issue Nov 18, 2022 · 3 comments

Comments

@rsr-maersk
Copy link

rsr-maersk commented Nov 18, 2022

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),

@slipjig
Copy link

slipjig commented Feb 13, 2023

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
Copy link

slipjig commented Feb 13, 2023

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

@MoonStorm
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants