哪一个快速执行JsonConvert.DeserializeObject或c#中的自定义模型绑定

时间:2017-12-07 14:11:48

标签: c# entity-framework linq

我想知道哪一个表现得更快 来自JsonConvert.DeserializeObject或自定义模型绑定 例如: 我的ViewModel类:

public class AssessmentViewModel : BaseViewModel
{
    public Guid AssessmentGUID { get; set; }

    public string AssessmentCategory { get; set; }

    public string AssessmentType { get; set; }

    public string AssessmentName { get; set; }

    public string AssessmentNameEnglish { get; set; }

    public string AssessmentInstruction { get; set; }

    public string AssessmentInstructionEnglish { get; set; }

    public int? SequenceNum { get; set; }

    public int? MaxScore { get; set; }

    public bool? IsNegativeMarking { get; set; }

    public decimal? NegativeRatio { get; set; }

    public List<StringMapDDLViewModel> AssessmentCategoryDDList { get; set; }

    public List<StringMapDDLViewModel> AssessmentTypeDDList { get; set; }

    public List<FOFormSectionViewModel> FOFormSectionList { get; set; }

    public List<StringMapDDLViewModel> FieldTypeList { get; set; }

    public List<StringMapDDLViewModel> ValidationTypeList { get; set; }
}

我正在调用存储过程并返回100万个数据。 所以我的问题是从下面的代码中执行得更快:

方法1:序列化结果然后反序列化。

 var assessmentList = db.AssessmentSP(Constant.ActionGetAll, null, status).ToList<AssessmentSP_Result>();
 objALVM.AssessmentList = JsonConvert.DeserializeObject<List<AssessmentViewModel>>(JsonConvert.SerializeObject(assessmentList));

方法2:逐个属性绑定

 var assessmentList = db.AssessmentSP(Constant.ActionGetAll, null, status).ToList<AssessmentSP_Result>().ToList();
                objALVM.AssessmentList = assessmentList.Select(x => new AssessmentViewModel()
                {
                     AssessmentGUID = x.AssessmentGUID,
                     AssessmentType = x.AssessmentType,
                     AssessmentName = x.AssessmentName,
                     AssessmentNameEnglish = x.AssessmentNameEnglish,
                     AssessmentInstruction = x.AssessmentInstruction,
                     AssessmentInstructionEnglish = x.AssessmentInstructionEnglish,
                     SequenceNum = x.SequenceNum,
                     MaxScore = x.MaxScore,
                     IsNegativeMarking = x.IsNegativeMarking,
                     NegativeRatio = x.NegativeRatio,
                }).ToList();

0 个答案:

没有答案