AutoMapping Custom Collections with FluentNHibernate
Asked Answered
H

1

2

I am retrofitting a very large application to use NHibernate as it's data access strategy. Everything is going well with AutoMapping. Luckily when the domain layer was built, we used a code generator. The main issue that I am running into now is that every collection is hidden behind a custom class that derives from List<>. For example

public class League
{
   public OwnerList owners {get;set;}
}
public class OwnerList : AppList<Owner>  { }
public class AppList<T> : List<T>  { }

What kind of Convention do I have to write to get this done?

Higher answered 24/5, 2010 at 19:15 Comment(2)
"Luckily when the domain layer was built, we used a code generator" - I fail to see how that would be a good thing. Exposing concrete list types is a big design mistake.Hutchison
It's a good thing that there was uniformity between the domain and the database, so a direct domain mapping is easy.Higher
F
2

I don't think you're going to be able to achieve this with a convention. You will have to create an auto mapping override and then do the following:

mapping.HasMany(l => a.owners).CollectionType<OwnerList>();
Forme answered 24/5, 2010 at 22:55 Comment(1)
This isn't a good solution, but it's the only one that works.Higher

© 2022 - 2024 — McMap. All rights reserved.