0

My entity has besides other properties Keyword property which is of type list of strings.

public virtual IList<string> Keywords { get; set; }

so I tried to map this property using conformist mapping by code approach simple as possible like this

Property(x => x.Keywords);

but I'm getting following exception

NHibernate.MappingException : Could not determine type for: System.Collections.Generic.IList`1[[System.String, mscorlib, Version=4.0.0.0,.....

6
  • How's Keywords represented in your database if you don't mind me asking ? Commented Sep 17, 2013 at 10:20
  • as text field separated by commas. Commented Sep 17, 2013 at 10:24
  • How is your DB model? Commented Sep 17, 2013 at 10:27
  • @AlessandroD'Andria My db model is fine thank you :) What do you mean exactly ? Commented Sep 17, 2013 at 10:29
  • Hehehe, as @DimitarDimitrov point, how you represents KeyWords in DB, eg: I have a table Document with a relation many to many with a table KeyWord. Commented Sep 17, 2013 at 10:32

1 Answer 1

1

You could map this to a private string field and then use string.Split in your Keywords getter to get a list.

public class MyClass {
    private string _keywords;

    public virtual IEnumerable<string> Keywords {
        get { return _keywords.Split(','); }
        set { _keywords = string.Join(value, ","); }
    }
}

I am not familiar with mapping by code that NH uses (I use FluentNH) but your mapping would probably be something like this:

Map("_keywords", map => {
    map.Access(Access.Field);
    // ...
});
Sign up to request clarification or add additional context in comments.

1 Comment

It's right but use public virtual string DbKeyWords { get; set; } instead of _keyword or NHibernate cannot map.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.