2012-11-05 45 views
1

我有一個對象調用國家和另一個電話CounytryRegions如快遞下面Petapoco - 無法自動加入

[TableName("Countries"), 
PrimaryKey("Code", autoIncrement = false)] 
public class Country 
{ 
    public Country() 
    { 
     this.CountryRegions = new List<CountryRegion>(); 
    } 

    public string Code { get; set; } 
    public string Name { get; set; } 

    [Foliaco.DataAccess.ResultColumn()] 
    public List<CountryRegion> CountryRegions { get; set; } 

} 

[TableName("CountryRegions"), 
PrimaryKey("Code", autoIncrement = false)] 
public class CountryRegion 
{ 
    public CountryRegion() 
    { 
     this.Country = new Country(); 
    } 

    public string Code { get; set; } 
    public string Name { get; set; } 

    public string CountryCode { get; set; } 

    [Foliaco.DataAccess.ResultColumn()] 
    public Country Country { get; set; } 

} 

如果我執行下面

Country country = this.DB.Fetch<Country,CountryRegion>("select * from dbo.countries c join dbo.countryregions cr on c.Code = cr.CountryCode where c.Code = @0","US").FirstOrDefault(); 

的SQL,我期望得到的國家/地區的CountryRegions屬性將所有關聯的記錄都記錄到該國家/地區,但我卻得到以下錯誤

無法自動加入CountryRegion

感謝您的幫助

+0

我想我發現問題根據他們的文檔我需要crate一個Relator類來加載列表。 [鏈接](http://www.toptensoftware.com/Articles/115/PetaPoco-Mapping-One-to-Many-and-Many-to-One-Relationships)請參閱第一部分到多部分 –

回答

2

我想我找到他們的資料,根據我需要裝箱房地產經紀人類加載列表請參見一對多的Petapoco Documentation的問題,我也發現了這個幫手類OneTOMany,使地產經紀人類更通用

+0

Petapoco非常棒,當你想要做你在現實世界中沒有做過的事情,但只要你做好運好友。 –

1

我剛剛遇到了這個錯誤使用NPoco庫,它基於PetaPoco。

在我的情況下,問題是我打電話.Fetch而不是.FetchOneToMany