使用模板实例化新的DynamicParameters会产生空的DynamicParameters

时间:2018-07-19 13:38:27

标签: c# dapper dynamicparameters

这是我的对象

public class DispatcherInfo
{
    public bool isEnabled { get; set; }
    public string applicationFileNameTemplateString { get; set; }
    public string md5FileNameTemplateString { get; set; }
    public string archiveMd5FileNameTemplateString { get; set; }
    public string archiveFileNameTemplateString { get; set; }
    public int applicationDispatcherTypeId { get; set; }
    public bool useCarrierReviewDestination { get; set; }
    public int ApplicationWriter_applicationWriterTypeId { get; set; }
    public int ApplicationWriter_minApplicationCount { get; set; }
    public int? ApplicationWriter_maxApplicationCount { get; set; }
    public string ApplicationWriter_publicKeyName { get; set; }
    public string ApplicationWriter_sourceDocumentFilePath { get; set; }
    public string ApplicationWriter_headerTemplateString { get; set; }
    public string ApplicationWriter_footerTemplateString { get; set; }
    public int? ApplicationWriter_encodingTypeId { get; set; }
    public string ApplicationWriter_delimiter { get; set; }
    public bool? ApplicationWriter_writesColumnNames { get; set; }
    public string ApplicationWriter_pluginTypeName { get; set; }
    public string ApplicationWriter_pluginAssemblyName { get; set; }
    public bool ApplicationWriter_shouldFlattenPdf { get; set; }
    public bool hasSchedule { get; set; }
    public bool? Schedule_isRealTime { get; set; }
    public DateTime? Schedule_startDate { get; set; }
    public DateTime? Schedule_endDate { get; set; }
    public int? Schedule_recurrenceTypeId { get; set; }
    public int? Schedule_interval { get; set; }
    public int? Schedule_minute { get; set; }
    public int? Schedule_hour { get; set; }
    public int? Schedule_weekdayId { get; set; }
    public int? Schedule_dayOfMonth { get; set; }
    public string Schedule_pluginTypeName { get; set; }
    public string Schedule_pluginAssemblyName { get; set; }
    public bool hasPrimaryTransmitter { get; set; }
    public int? PrimaryTransmitter_transmissionTypeId { get; set; }
    public string PrimaryTransmitter_destinationUriTemplateString { get; set; }
    public bool? PrimaryTransmitter_ftpConnectsInActiveMode { get; set; }
    public string PrimaryTransmitter_ftpUserName { get; set; }
    public string PrimaryTransmitter_ftpPassword { get; set; }
    public string PrimaryTransmitter_emailSubjectTemplateString { get; set; }
    public string PrimaryTransmitter_emailBodyTemplateString { get; set; }
    public string PrimaryTransmitter_emailReplyToAddress { get; set; }
    public string PrimaryTransmitter_emailRecipientList { get; set; }
    public string PrimaryTransmitter_emailCarbonCopyList { get; set; }
    public string PrimaryTransmitter_emailBlindCarbonCopyList { get; set; }
    public string PrimaryTransmitter_emailFooterTemplateString { get; set; }
    public bool? PrimaryTransmitter_sendAsAttachment { get; set; }
    public string PrimaryTransmitter_pluginTypeName { get; set; }
    public string PrimaryTransmitter_pluginAssemblyName { get; set; }
    public bool hasCarrierReviewTransmitter { get; set; }
    public int? CarrierReviewTransmitter_transmissionTypeId { get; set; }
    public string CarrierReviewTransmitter_destinationUriTemplateString { get; set; }
    public bool? CarrierReviewTransmitter_ftpConnectsInActiveMode { get; set; }
    public string CarrierReviewTransmitter_ftpUserName { get; set; }
    public string CarrierReviewTransmitter_ftpPassword { get; set; }
    public string CarrierReviewTransmitter_emailSubjectTemplateString { get; set; }
    public string CarrierReviewTransmitter_emailBodyTemplateString { get; set; }
    public string CarrierReviewTransmitter_emailReplyToAddress { get; set; }
    public string CarrierReviewTransmitter_emailRecipientList { get; set; }
    public string CarrierReviewTransmitter_emailCarbonCopyList { get; set; }
    public string CarrierReviewTransmitter_emailBlindCarbonCopyList { get; set; }
    public string CarrierReviewTransmitter_emailFooterTemplateString { get; set; }
    public bool? CarrierReviewTransmitter_sendAsAttachment { get; set; }
    public string CarrierReviewTransmitter_pluginTypeName { get; set; }
    public string CarrierReviewTransmitter_pluginAssemblyName { get; set; }
    public Guid? ApplicationDispatcherFormMap_formGuid { get; set; }
    public int newApplicationDispatcherId { get; set; }
}

从理论上讲,我应该能够做这样的事情……

var dispInfo = new DispatcherInfo { /* a number of Properties are given values */ };
var parameters = new DynamicParameters(dispInfo);
parameters.Output(dispatcherInfo, info => info.newApplicationDispatcherId);

但是我的参数对象为空,parameters上ParameterNames属性的结果视图显示为:Enumeration yielded no results

在另一面,这可行...

var dispInfo = new DispatcherInfo { /* a number of Properties are given values */ };
dispInfo.GetType().GetProperties().Each(prop =>
{
    parameters.Add(prop.Name, prop.GetValue(dispatcherInfo));
});

parameters.Add("newApplicationDispatcherId",0, direction: ParameterDirection.Output);

但是以这种方式添加我的输出似乎仅在某些时间有效。如果我用第二种方法更新参数,但同时用两种方法添加输出(所以parameters.Addparameters.Output似乎都是最可靠的输出。

这使我认为我用作模板的对象有问题,但是我似乎无法弄清楚它是什么。我喜欢用模板实例化参数的语法要比遍历“属性”并将它们一个接一个地添加更多。

有什么想法吗?

0 个答案:

没有答案