【问题标题】:Petapoco - Can't auto joinPetapoco - 无法自动加入
【发布时间】:2012-11-05 01:44:17
【问题描述】:

我有一个对象调用 Country 和另一个调用 CounytryRegions 如下所示

[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; }

}

如果我执行下面的sql

 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();

我希望在 Country 类的 CountryRegions 属性上获取该国家/地区的所有相关记录,但我得到了以下错误

无法自动加入 CountryRegion

感谢您的帮助

【问题讨论】:

  • 我想我根据他们的文档找到了问题,我需要创建一个 Relator 类来加载列表。 link 参见“一对多”部分

标签: .net model-view-controller orm petapoco micro-orm


【解决方案1】:

我想我根据他们的文档发现了问题我需要创建一个房地产经纪人类来加载列表,请参阅Petapoco Documentation 上的一对多部分,我还发现了这个帮助类 OneTOMany房地产经纪人类更通用

【讨论】:

  • Petapoco 非常适合您想做一些您在现实世界中不会做的事情,但只要您做的好,伙计。
  • ..这就是为什么你应该提供代码而不是链接:(
【解决方案2】:

我刚刚使用基于 PetaPoco 的 NPoco 库遇到了这个错误。

我的问题是我打电话给.Fetch而不是.FetchOneToMany

【讨论】:

    猜你喜欢
    • 2012-01-31
    • 2015-01-21
    • 2023-03-24
    • 2011-08-27
    • 1970-01-01
    • 2021-07-08
    • 2013-05-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多