PetaPoco 返回错误的 ID

发布于 2024-11-30 23:59:33 字数 737 浏览 3 评论 0原文

我有以下模型和方法:

[PetaPoco.TableName("TestStep")]
[PetaPoco.PrimaryKey("ID")]
public class TestStep
{
    public int ID { get; set; }

    public int ParentID { get; set; }

    public string Name { get; set; }

    public string Details { get; set; }
}

 public IEnumerable<TestStep> GetById(int ID)
        {
            var db = new PetaPoco.Database("TestProcedureDB");

            return db.Query<TestStep>(@"SELECT * FROM TESTSTEP TS 
                                       INNER JOIN TESTSTEPLINK L ON L.STEPID = TS.ID
                                       WHERE L.TESTID = @0", ID);

        }

填充 POCO 时,ID 属性值是 TESTSTEPLINK 表中 ID 列的值。如果我将查询更改为返回 SELECT TS.* 则一切正常。这是一个错误还是我错过了什么?

I have the following model and methods:

[PetaPoco.TableName("TestStep")]
[PetaPoco.PrimaryKey("ID")]
public class TestStep
{
    public int ID { get; set; }

    public int ParentID { get; set; }

    public string Name { get; set; }

    public string Details { get; set; }
}

 public IEnumerable<TestStep> GetById(int ID)
        {
            var db = new PetaPoco.Database("TestProcedureDB");

            return db.Query<TestStep>(@"SELECT * FROM TESTSTEP TS 
                                       INNER JOIN TESTSTEPLINK L ON L.STEPID = TS.ID
                                       WHERE L.TESTID = @0", ID);

        }

When the POCO is populated, the ID property value is that of the ID column in the TESTSTEPLINK table. If I change the query to return SELECT TS.* then all is ok. Is this a bug or am I missing something?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

﹏雨一样淡蓝的深情 2024-12-07 23:59:33

PetaPoco 将遍历您所有的退货列并映射它们。
首先,它会从表 TESTSTEP 映射 Id,然后再次找到 Id,并覆盖之前设置的值。

如果您正在进行这样的联接并且只需要特定信息,您应该只指定您想要返回的列(否则您将返回比需要的更多的数据,这是一个性能问题)

,或者按照您所做的那样修复它使用 TS.* 确保仅映射第一个表中的列。

PetaPoco will go through all your return columns and map them.
First it will map Id from the table TESTSTEP, then it finds Id again and so it overrides the previously set value.

If you are doing a join like this and only want specific information, you should either only specify the columns you want to return (otherwise you are bringing back more data than needed which is a performance issue)

or do as you did to fix it by using TS.* to ensure only the columns from the first table are mapped.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文