本文介绍了我应该在我的类中使用哪个NHibernate.Mapping.Attributes来映射字典?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用NHibernate,我直接用属性映射我的对象。我已经看到类似的问题,但大多数情况下,人们使用映射文件...或者他们给出不再存在的链接的答案:)对于下面的类,我必须为属性表添加哪些属性一个IDictionary?我猜这是像[Map],但是哪些属性和/或元素?我在哪里可以找到一些文档?

  [Class(Table =SpecificitySets,Name =ZslSpecificityTable)] 
public class SpecificityTable
{
[Id(0,TypeType = typeof(ulong),Name =Id)]
[Generator(1,Class =native)]
public uint Id

[Map(Name =specificityMapping,Table =SpecificityMapping)]
//然后?
public virtual IDictionary< string,double>表{get;私人集合}

// ...
}


解决方案

在某些尝试以后实际上并不困难:

  [Class(Table =SpecificitySets ,name =ZslSpecificityTable)] 
public class SpecificityTable
{
[Id(0,TypeType = typeof(ulong),Name =Id)]
[Generator 1,Class =native)]
public uint Id

[Map(1,Name =Table,Table =SpecificityMapping)]
[Key ,Column =SpecTableId)]
[Index(3,Column =Term,Type =string)]
[Element(4,Column =Value,Type =double )]
public virtual IDictionary< string,double>表{get;私人集合}

// ...
}

1


I'm using NHibernate and I map my objects directly with attributes. I've seen similar questions but most of the case people use mapping files... or they give answers with links that don't exist anymore :) For the following class, which attributes do I have to add for the property Table which is a IDictionary? I guess it's something like [Map] but with which attributes and/or elements? Where could I find some documentation?

[Class(Table = "SpecificitySets", Name = "ZslSpecificityTable")]
public class SpecificityTable
{
    [Id(0, TypeType = typeof(ulong), Name = "Id")]
    [Generator(1, Class = "native")]
    public uint Id 

    [Map(Name = "specificityMapping", Table = "SpecificityMapping")]
    // and then ??
    public virtual IDictionary<string, double> Table { get; private set; }

    // ...
}
解决方案

after some tries it was not that difficult actually:

[Class(Table = "SpecificitySets", Name = "ZslSpecificityTable")]
public class SpecificityTable
{
    [Id(0, TypeType = typeof(ulong), Name = "Id")]
    [Generator(1, Class = "native")]
    public uint Id 

    [Map(1, Name = "Table", Table = "SpecificityMapping")]
    [Key(1, Column = "SpecTableId")]
    [Index(3, Column = "Term", Type="string")]
    [Element(4, Column = "Value", Type="double")]
    public virtual IDictionary<string, double> Table { get; private set; }

    // ...
}

1

这篇关于我应该在我的类中使用哪个NHibernate.Mapping.Attributes来映射字典?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 10:06