Ale*_*lex 7 c# fluent-nhibernate
我的模型看起来像这样:
public class Product
{
public string Name {get; set;}
public string Description {get; set;}
public double Price {get; set;}
public List<string> Features {get; set;}
}
Run Code Online (Sandbox Code Playgroud)
我希望我的数据库表是平的 - 列表应该存储为分隔字符串:功能一|功能二|功能三例如.
从db中检索时,它应将每个项目放回List中
这可能吗?
Dan*_*anB 12
我在我当前的项目中做了同样的事情,只是我将枚举的集合作为管道分隔的数字.它的工作方式相同.
public class Product
{
protected string _features; //this is where we'll store the pipe-delimited string
public List<string> Features {
get
{
if(string.IsNullOrEmpty(_features)
return new List<String>();
return _features.Split(new[]{"|"}, StringSplitOptions.None).ToList();
}
set
{
_features = string.Join("|",value);
}
}
}
public class ProductMapping : ClassMap<Product>
{
protected ProductMapping()
{
Map(x => x.Features).CustomType(typeof(string)).Access.CamelCaseField(Prefix.Underscore);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3266 次 |
| 最近记录: |