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

Can't override key colum name in JoinedSubClass Automapping #42

Closed
jagregory opened this issue Jul 21, 2011 · 9 comments · Fixed by #468
Closed

Can't override key colum name in JoinedSubClass Automapping #42

jagregory opened this issue Jul 21, 2011 · 9 comments · Fixed by #468
Labels
Milestone

Comments

@jagregory
Copy link
Collaborator

See: https://groups.google.com/forum/#!topic/fluent-nhibernate/xblilnwhGWE/discussion

@chester89
Copy link
Collaborator

On it. Shouldn't be too hard to fix

@chester89
Copy link
Collaborator

Well, I don't know why, but given the code provided, I can't even get the derived type to be automapped - the ClassMaping I receive from AutoPersistenceModel is null. Need to revisit tomorrow

@chester89
Copy link
Collaborator

That's really strange - when I created the sample project with the configuration provided, generated sql shows that the problem exists, as described. But in tests I can't reproduce it - at all.

@shiznit013
Copy link

I spent several hours on this problem yesterday, and thought that I was doing something wrong. It seems that JoinedSubClass ignores whatever column name you supply it. I have a Person class with an Employee subclass. Both classes have an Id property, but the column names underlying them are different (PersonID and EmployeeID). When automapped, the subclass key column is generated as ParentClassName_id (Person_id in my case), disregarding the column name supplied to the override mapping.JoinedSubClass<Employee>("EmployeeID");

Below is a simplified version of my situation:

namespace Domain.Model
{
    public abstract class Entity<T>
    {
        public virtual T Id { get; set; }
    }

    public class Person : Entity<Guid>
    {        
    }

    public class Employee : Person
    {
    }

    public class PersonMappingOverride : IAutoMappingOverride<Person>
    {
    public void Override(AutoMapping<Person> mapping)
    {
        mapping.Id(x => x.Id, "PersonID");
        mapping.JoinedSubClass<Employee>("EmployeeID");
    }
    }
}

Which generates (I stripped out the fluff):

<hibernate-mapping>
  <class name="Person">
    <id name="Id">
      <column name="PersonID" />
      <generator class="guid.comb" />
    </id>
    <joined-subclass name="Employee">
      <key>
        <column name="Person_id" />
      </key>
    </joined-subclass>
  </class>
</hibernate-mapping>

Luckily, our project is setup to use all 3 flavors of mapping, so I can just map them fluently for now.

@chester89
Copy link
Collaborator

yeah, that situation need proper debugging, from what I understand. Somewhere in there joined subclass isn't honored. There's more - FNH doesn't even generate ClassMapping instance in that case, which is really weird

@shiznit013
Copy link

If I put an override in the subclass, it does honor those properties in the joined-subclass portion of the mapping file. It just won't honor the key column name.

@ltvan
Copy link

ltvan commented Apr 2, 2018

How's about this bug now?

@ltvan
Copy link

ltvan commented Jun 15, 2018

I used JoinedSubClassConvention to override key column name, but there is another headache issue that take me days to fix: do not use ForeignKey.EndsWith("Id"), otherwise the joined-subclass column always add a column named <ParentClass>Id.

@hazzik hazzik modified the milestones: Release 1.3, 3.0.0 Sep 20, 2020
@hazzik hazzik changed the title Can't override key colum name in JoinedSubClass Can't override key colum name in JoinedSubClass Automapping Sep 20, 2020
hazzik added a commit that referenced this issue Sep 20, 2020
* Deprecate inline subclass methods on AutoMapping

Closes #42
@hazzik
Copy link
Member

hazzik commented Sep 20, 2020

With #468 you can do following:

public class PersonMappingOverride : IAutoMappingOverride<Person>
{
    public void Override(AutoMapping<Employee> mapping)
    {
        mapping.KeyColumn("EmployeeID");
    }
}

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

Successfully merging a pull request may close this issue.

5 participants