1

我在http://teamcity.codebetter.com/project.html?projectId=project41使用 filehelper 2.9.9将我的数据导出为 CSV 格式。
我使用 [FieldNotInFile] 忽略一些我不想导出的字段。
当我的数据库更改时,我还使用 MetadataType 来避免编辑模型
这是我的代码:

public partial class book
{
    public long id { get; set; }
    public string book { get; set; }
    public virtual author author { get; set; }
}


[MetadataType(typeof(bookMetadata))]
[DelimitedRecord(",")]
public partial class book
{

}

public class bookMetadata
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    [FieldNotInFile] //It don't work at all
    public long id;

    [DisplayName("Book")]
    public string book { get; set; }
    public author author;



    [FieldNotInFile] //It don't work at all
    private author _author;

    public author author
    {
        get { return _author; }
        set { _author = value; }
    }
}

我的问题是当我在元数据中应用 [FieldNotInFile] 属性时,它根本不起作用。
当我将字段封装在由数据库生成的模型中并应用属性时,它可以完美运行。但是,每次数据库更改时,我都必须手动合并它们。

任何帮助表示赞赏
提前感谢

4

1 回答 1

2

This is probably the limitation of FileHelper (it probably just uses reflection to find attributes on the serialized class and is not aware of metadata buddy class).

Try creating a Model class for it, copy the data using AutoMapper and that apply your attribute to the Model class. Editing generated code is to error-prone, IMHO.

于 2011-11-29T09:18:46.743 回答