3

If I have a POCO class with ResultColumn attribute set and then when I do a Single<Entity>() call, my result column isn't mapped. I've set my column to be a result column because its value should always be generated by SQL column's default constraint. I don't want this column to be injected or updated from business layer. What I'm trying to say is that my column's type is a simple SQL data type and not a related entity type (as I've seen ResultColumn being used mostly on those).

Looking at code I can see this line in PetaPoco:

// Build column list for automatic select
QueryColumns = (   from c in Columns
                   where !c.Value.ResultColumn
                   select c.Key
               ).ToArray();

Why are result columns excluded from automatic select statement because as I understand it their nature is to be read only. So used in selects only. I can see this scenario when a column is actually a related entity type (complex). Ok. but then we should have a separate attribute like ComputedColumnAttribute that would always be returned in selects but never used in inserts or updates...

Why did PetaPoco team decide to omit result columns from selects then?
How am I supposed to read result columns then?

Robert Koritnik
  • 103,639
  • 52
  • 277
  • 404

1 Answers1

2

I can't answer why the creator did not add them to auto-selects, though I would assume it's because your particular use-case is not the main one that they were considering. If you look at the examples and explanation for that feature on their site, it's more geared towards extra columns you bring back in a join or calculation (like maybe a description from a lookup table for a code value). In these situations, you could not have them automatically added to the select because they are not part of the underlying table.

So if you want to use that attribute, and get a value for the property, you'll have to use your own manual select statement rather than relying on the auto-select.

Of course, the beauty of using PetaPoco is that you can easily modify it to suit your needs, by either creating a new attribute, like you suggest above, or modifying the code you showed to not exclude those fields from the select (assuming you are not using ResultColumn in other join-type situations).

patmortech
  • 10,139
  • 5
  • 38
  • 50