次のコードで、KeyValuePair のリストを作成しようとしています。ただし、常に空です。なんで?
デバッグ時に、プロパティの名前に Role という単語が含まれていることがわかります。タイプ tblJob も確認しましたが、これらのプロパティはすべて文字列です。スクリーンショットを参照してください。
tblJob job = (tblJob)entity.Entity;
var listOfRolesnamesAndValues =
typeof(tblJob) //Get all properties that contains the Role name on it.
.GetProperties(BindingFlags.Public)
.Where(p => p.Name.Contains("Role") && p.PropertyType == typeof(string))
.Select(p => new KeyValuePair<string, string>(p.Name, p.GetValue(job, null) as string))
.ToList();
public partial class tblJob
{
public string ClientCode { get; set; }
public string ClientName { get; set; }
public string ClientURL { get; set; }
public string JobCode { get; set; }
public string JobName { get; set; }
public string JobURL { get; set; }
public string LongJobDescription { get; set; }
public string iPowerLink { get; set; }
public string Industry { get; set; }
public string ChargeType { get; set; }
public string Product { get; set; }
public string ProductGroup { get; set; }
public Nullable<decimal> GrossEstimatedFee { get; set; }
public string LineOfService { get; set; }
public string LineOfServiceCode { get; set; }
public string LineOfServiceRole { get; set; }
public string LineOfServiceRolePD { get; set; }
public string LineOfServiceRoleMAPO { get; set; }
public string LineOfServiceRoleMA { get; set; }
public string LineOfServiceRoleSTAFF { get; set; }
public string BusinessUnit { get; set; }
public string BusinessUnitCode { get; set; }
public string BusinessUnitRole { get; set; }
public string BusinessUnitRolePD { get; set; }
public string BusinessUnitRoleMAPO { get; set; }
public string BusinessUnitRoleMA { get; set; }
public string BusinessUnitRoleSTAFF { get; set; }
public string OperatingUnit { get; set; }
public string OperatingUnitCode { get; set; }
public string OperatingUnitRole { get; set; }
public string OperatingUnitRolePD { get; set; }
public string OperatingUnitRoleMAPO { get; set; }
public string OperatingUnitRoleMA { get; set; }
public string OperatingUnitRoleSTAFF { get; set; }
public int Terminated { get; set; }
public Nullable<System.DateTime> TerminatedDate { get; set; }
public string JobPartner { get; set; }
public string JobManager { get; set; }
public string JobDirector { get; set; }
public string BillPartner { get; set; }
public string BillManager { get; set; }
public string JobTeam { get; set; }
public string JobEntity { get; set; }
public string ProductCode { get; set; }
public string BillContact { get; set; }
public Nullable<int> Confidential { get; set; }
}