Pregunta

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)

¿Fue útil?

Solución

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 -> http://www.toptensoftware.com/Articles/101/PetaPoco-Working-with-Joins

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top