出于备份的原因,我需要写一个工作,得到所有的记录在一个数据库旧thena某些数据,保存到csv和发送到远程存储,然后从数据库中删除记录
因此,对于每个类,我创建了一个相同的类,其中包含所有在csv上写入的信息(参见下面的示例),并且没有对象引用,一切都很好。问题是:当我修改主类时,我需要记住更新模型类。
有办法避免吗?
编辑:我的问题是:有一种方法可以指定FieldQuoted,DelimitedRecord,并指定FileHelper中忽略哪个字段?
示例
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace backend.DataModel
{
using System;
using System.Collections.Generic;
public partial class Attachment
{
public string Id { get; set; }
public int AttachmentTypeCode { get; set; }
public string AttachmentContent;
public System.DateTime CreationDate { get; set; }
public string Md5 { get; set; }
public virtual AttachmentType AttachmentType1 { get; set; }
}
}
namespace BackupDatabase.Model
{
[DelimitedRecord(";")]
[IgnoreEmptyLines()]
public class AttachmentBackupModel
{
[FieldQuoted('"', QuoteMode.AlwaysQuoted)]
public string Id;
public int AttachmentTypeCode;
[FieldQuoted('"', QuoteMode.AlwaysQuoted)]
public string ReferenceId;
[FieldQuoted('"', QuoteMode.AlwaysQuoted)]
public string AttachmentContent;
[FieldConverter(ConverterKind.Date, "dd/MM/yyyy HH:mm:ss:fff")]
public DateTime CreationDate;
[FieldQuoted('"', QuoteMode.AlwaysQuoted)]
public string Md5;
public AttachmentBackupModel() { }
public AttachmentBackupModel(Attachment attachment)
{
Id = attachment.Id;
AttachmentType = attachment.AttachmentType;
AttachmentContent = attachment.AttachmentContent;
Md5 = attachment.Md5;
}
}
}
1条答案
按热度按时间beq87vna1#
使用DelimitedClassBuilder从Entity框架模型数据构建Record定义的通用解决方案。