Iterate through properties and values of an object returned via a linq query on a domain model

后端 未结 3 2006
旧巷少年郎
旧巷少年郎 2021-02-01 01:26

I have a custom entity in a relational database that I have mapped to the CLR via a domain model. So by using the following statement, I can pull in an entity from my database i

3条回答
  •  执笔经年
    2021-02-01 02:12

    GetProperties indeed is the correct method.

    To get rid of the compiler error, change your code to this:

    var value = reportField.GetValue(inspection, null);
    

    You need to pass the instance from which you want to obtain the value, as a PropertyInfo object is not bound to any specific class instance.


    Please consider following the standard .NET naming rules.

    This would lead to the following:

    NewSystemAlarm instead of New_systemAlarm
    newSystemAlarm or _newSystemAlarm instead of _new_systemAlarm
    NewTestInspectionExtensionBases instead of New_testinspectionExtensionBases
    NewTestInspectionId instead of New_testinspectionId

提交回复
热议问题