SQLから返されたフィールドとリストを含むlstContractor
C#クラス()のリスト()にデータを入力しようとしています。IDでリンクされた複数のテーブルを返します。contractor
DataSet
DataSet
テーブルから必要な唯一のフィールドである1つのフィールドを除いて、すべてが機能するようになりました。LINQを使用して選択しようとすると、System.Data.EnumerableRowCollection
代わりに1[System.String]`が表示されます。フィールドの内容の。
私のコードは次のようになります:
lstContractor = dsContractor.Tables[0].AsEnumerable().Select(contractor => new Contractor
{
intContractorId = contractor.Field<int>("ID"),
strFirstName = contractor.Field<string>("FirstName"),
strLastName = contractor.Field<string>("LastName"),
strProfile = dsContractor.Tables[7].AsEnumerable().Where(profile => profile.Field<int>("ContractorId") == contractor.Field<int>("Id")).
Select(profile => profile.Field<string>("ContractorProfile")).ToString(),
// populate addresses
Address = dsContractor.Tables[6].AsEnumerable().Where(address => address.Field<int>("ContractorId") == contractor.Field<int>("Id")).
Select(address => new Address
{
intId = address.Field<int>("ContractorId"),
strAddressLine1 = address.Field<string>("AddressLine1"),
strAddressLine2 = address.Field<string>("AddressLine2"),
strAddressLine3 = address.Field<string>("AddressLine3"),
strAddressLine4 = address.Field<string>("AddressLine4"),
strAddressLine5 = address.Field<string>("AddressLine5"),
strPostCode = address.Field<string>("PostCode")
}).ToList<Address>(),
// populate industries
Industry = dsContractor.Tables[1].AsEnumerable().Where(Industry => Industry.Field<int>("ContractorId") == contractor.Field<int>("Id")).
Select(target => new Industry
{
intId = target.Field<int>("ContractorId"),
strIndustryName = target.Field<string>("IndustryName")
}).ToList<Industry>(),
// populate key skills
KeySkill = dsContractor.Tables[2].AsEnumerable().Where(KeySkill => KeySkill.Field<int>("ContractorId") == contractor.Field<int>("Id")).
Select(target => new KeySkill
{
intId = target.Field<int>("ContractorId"),
strKeySkillName = target.Field<string>("KeySkillName")
}).ToList<KeySkill>(),
// populate email addresses
EmailAddress = dsContractor.Tables[3].AsEnumerable().Where(EmailAddress => EmailAddress.Field<int>("ContractorId") == contractor.Field<int>("Id")).
Select(target => new EmailAddress
{
intId = target.Field<int>("ContractorId"),
strEmailAddress = target.Field<string>("EmailAddress"),
strEmailType = target.Field<string>("EmailType")
}).ToList<EmailAddress>(),
// populate phone numbers
PhoneNumber = dsContractor.Tables[4].AsEnumerable().Where(PhoneNumber => PhoneNumber.Field<int>("ContractorId") == contractor.Field<int>("Id")).
Select(target => new PhoneNumber
{
intId = target.Field<int>("ContractorId"),
strPhoneNumberType = target.Field<string>("PhoneType"),
strPhoneNumber = target.Field<string>("PhoneNumber")
}).ToList<PhoneNumber>(),
Geography = dsContractor.Tables[5].AsEnumerable().Where(PhoneNumber => PhoneNumber.Field<int>("ContractorId") == contractor.Field<int>("Id")).
Select(target => new Geography
{
intId = target.Field<int>("ContractorId"),
strGeography = target.Field<string>("GeographyName")
}).ToList<Geography>(),
}).ToList<Contractor>();
クラスは次のようになります。
public int intContractorId;
public string strFirstName;
public string strMiddleName;
public string strLastName;
public string strDescription;
public DateTime dtDOB;
public string strGender;
public string strProfile;
public int intIsFullTime;
public int intWorkMonday;
public int intWorkTuesday;
public int intWorkWednesday;
public int intWorkThursday;
public int intWorkFriday;
public int intWorkSaturday;
public int intWorkSunday;
public DateTime dtAvailableFrom;
public int intActive;
public decimal dcSubscrptionCost;
public DateTime dtRenewalDate;
public List<Address> Address;
public List<EmailAddress> EmailAddress;
public List<PhoneNumber> PhoneNumber;
public List<KeySkill> KeySkill;
public List<Geography> Geography;
public List<Industry> Industry;
public List<SubIndustry> SubIndustry;
問題のフィールドはstrProfile
ですが、フィールドに含まれる文字列ではなく、自分が自分であるコンテンツを取得している理由を一生理解できません。
デバッグモードでチェックしましたが、正しいデータがにありDataSet
ます。
私が何かを逃したかどうか私に知らせてください。
ありがとう