开发者

Fluent NHibernate Automap does not take into account IList<T> collections as indexed

I am using automap to map a domain model (simplified version):

public class AppUser : Entity
{
    [Required]
    public virtual string NickName { get; set; }

    [Required]
    [DataType(DataType.Password)]
    public virtual string PassKey { get; set; }

    [Required]
    [DataType(DataType.EmailAddress)]
    public virtual string EmailAddress { get; set; }
    public virtual IList<PreferencesDescription> PreferencesDescriptions { get; set; }
}

public class PreferencesDescription : Entity
{
    public virtual AppUser AppUser { get; set; }
    public virtual string Content{ get; set; }
}

The PreferencesDescriptions collection is mapped as an IList, so is an indexed collection (when I require standard unindexed collections I use ICollection).

The fact is that fluent nhibernate's automap facilities map my domain model as an unindexed collection (so there's no "position" property in the DDL开发者_如何学Python generated by SchemaExport).

¿How can I make it without having to override this very case - I mean, how can I make Fluent nhibernate's automap make always indexed collections for IList but not for ICollection


IList is not an indexed collection. You can access elements in an IList by index but their position is not stored in the database. You can't access an ICollection by index (without using extension methods) but it does have an AddAt method to add an object to the collection at an index.

If you need to store an objects position in the collection, map it as a map which equates to an IDictionary. I assume the automap will use map for a IDictionary collection types.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜