views:

47

answers:

2

Hi all,

I am trying to create a mapping file for the following Model using Fluent NHibernate. But, I am not sure of how to do the mapping for the List<string> in the mapping file.

    public class MyClass
    {
        public virtual Guid Id { get; set; }
        public virtual string Name { get; set; }
        public virtual List<string> MagicStrings { get; set; }
    }

    public class EnvironmentMapping : ClassMap<Models.Environment>
    {
        public EnvironmentMapping()
        {
            Id(x => x.Id);
            Map(x => x.Name);
            //HasMany(x => string)  What should this be ?
        }
    }

Help in this regard is much appreciated. Thanks!

+1  A: 

This is not quite what you are asking, but I just want to point out that FNH Automapping will map your class with absolutely no further help from the programmer - i.e. you don't need additional Mapping classes.

You just have to declare the member as an IList, instead of a List. (Actually, I thought you had to use IList for regular FNH mapping too).

One further point - there was a bug with automapping value types such as strings and ints, which was fixed very recently, so make sure you're using the latest FNH builds if you decide to go the Automapping route (which I highly recommend, BTW!).

Tom Bushell
+1 for suggesting automapping, but I just wanted to look through things and how they are done under the hood, thanks for the suggestion :)
Mahesh Velaga
A: 

I found a solution for my problem, in my situation I have to create a seperate table for MyStrings and have a foriegn key relation with MyClass.

Thanks for the suggestions! :)

Mahesh Velaga

related questions