DB へのクエリの結果を POCO に入力しようとしています。結果セットには複数の行があるため、各結果を繰り返し処理して POCO にデータを入力すると、次のエラーが表示されます。
私はどこを台無しにしていますか?
こんなふうになります:
【コントローラー.cs】
/// <summary>
/// Populates the inner Ads list
/// </summary>
public void FetchAds()
{
_ads = new List<Ad>();
using (var context = (ApartmentDataEntities) DbContextFactory.GetInstance().GetDbContext<ApartmentDataEntities>())
{
foreach (var config in context.Configurations)
{
_ads.Add(new AdModel(_basePath, config));
}
}
AdsReady.SafeTrigger(this, new AdArray { Ads = _ads.ToArray() });
}
[AdModel.cs] (POCO から継承)
public AdModel(String baseFolder, Configuration apartment)
{
_baseFolder = baseFolder;
GetAd(apartment);
}
/// <summary>
/// Populates the Ad from the Database
/// </summary>
private void GetAd(Configuration apartment)
{
PropertyId = apartment.Property.id;
PropertyName = apartment.Property.name;
PropertyPhone = apartment.Property.phone;
PropertyAddress = apartment.Property.address;
AreaName = apartment.Property.MapArea.areaName;
RegionName = apartment.Property.MapArea.Region.name;
PropertyZipCode = apartment.Property.zipCode;
ComissionRate = apartment.Property.comissionRate;
Images = apartment.Property.Images.Select(img => img.id).ToArray();
YearBuilt = apartment.Property.yearBuilt;
Features = apartment.Property.features;
Ammenities = apartment.Property.ammenities;
CommunitySpecial = apartment.Property.communitySpecial;
PetPolicy = apartment.Property.petPolicy;
Size = apartment.size;
Bathrooms = apartment.bathrooms;
Bedrooms = apartment.bedrooms;
Price = apartment.price;
PropertyImages = apartment.Property.Images.Select(img => img.imageContents).ToArray();
FloorplanImage = null;
Floorplan = null;
var configFloorplan = apartment.Images.SingleOrDefault();
if (configFloorplan == null) return;
FloorplanImage = configFloorplan.imageContents;
Floorplan = configFloorplan.id;
}