我是否误解了 PetaPoco.IgnoreAttribute?
我有一个包含服务公告的表格。对于这个表,我有一个 1:1 POCO - 只不过它包含一个额外的字段。在我的查询中,这是加入的作者用户名,该表仅包含作者 ID。
我认为我可以在该字段上附加一个 [Ignore]
属性,然后能够使用 POCO 进行插入/更新而不会出现问题? 我的问题是使用[Ignore]
属性时,BrukerNavn
字段未填充。 没有该属性,它会在插入/更新时爆炸。
[TableName("tblDriftsmelding")]
[PrimaryKey("DriftID")]
public class Driftsmelding
{
public int DriftID { get; set; }
[Column("tittel")] public string Tittel { get; set; }
public string Tekst { get; set; }
public string HTMLTekst { get; set; }
[Column("gyldigfra")] public DateTime? Fra { get; set; }
[Column("gyldigtil")] public DateTime? Til { get; set; }
[Column("publisert")] public bool Publisert { get; set; }
[Column("CreatedBy")] public int? BrukerID { get; set; }
public string BrukerNavn { get; set; }
}
这就是 POCO。该表是 1:1 映射,除了末尾的“BrukerNavn”字段。
select d.DriftID, d.Tekst, d.Created, d.gyldigtil, d.gyldigfra, d.publisert, d.tittel, d.HTMLTekst, d.createdby, b.brukerident as BrukerNavn
from tblDriftsmelding d
left outer join tblbruker b on d.CreatedBy = b.brukerid
order by DriftID desc
这是为 POCO 提供数据的查询。 (我也尝试过使用select d.*, b.brukerid
。没有区别)
(注意,实际问题在上面的文本中以粗体显示,因为它有点与其余文本)
I have a table containing service announcements. For this table I have a 1:1 POCO - except that it contains one extra field. In my query this is the joined in username of the author, the table contains just the author id.
I thought that I could just tack on an [Ignore]
attribute on this field, and then be able to use the POCO for inserts/updates without problems? My problem is that with the [Ignore]
attribute, the BrukerNavn
field is not filled. And without the attribute, it goes bang on insert/update.
[TableName("tblDriftsmelding")]
[PrimaryKey("DriftID")]
public class Driftsmelding
{
public int DriftID { get; set; }
[Column("tittel")] public string Tittel { get; set; }
public string Tekst { get; set; }
public string HTMLTekst { get; set; }
[Column("gyldigfra")] public DateTime? Fra { get; set; }
[Column("gyldigtil")] public DateTime? Til { get; set; }
[Column("publisert")] public bool Publisert { get; set; }
[Column("CreatedBy")] public int? BrukerID { get; set; }
public string BrukerNavn { get; set; }
}
This is the POCO. The table is a 1:1 mapping, except the "BrukerNavn" field at the end.
select d.DriftID, d.Tekst, d.Created, d.gyldigtil, d.gyldigfra, d.publisert, d.tittel, d.HTMLTekst, d.createdby, b.brukerident as BrukerNavn
from tblDriftsmelding d
left outer join tblbruker b on d.CreatedBy = b.brukerid
order by DriftID desc
This is the query that feeds the POCO. (I have also tried using select d.*, b.brukerid
. No difference)
(Note, the actual question is in bold in the above text, since it sort of got intermingled with the rest of the text)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您需要的是
[ResultColumn]
属性 - 如果您的查询包含该列的数据,它将填充该列,并且它不会用于插入和更新。您可以在这里查看更多信息 -> https://github.com/CollaboratingPlatypus/PetaPoco/wiki/Mapping-Pocos
I think what you need is the
[ResultColumn]
attribute - this will fill the column if your query contains data for it and it will not get used for inserts and updates.You can see more on it here -> https://github.com/CollaboratingPlatypus/PetaPoco/wiki/Mapping-Pocos