c# - ASP.Net MVC code first. How force a get only attrubute to be stored on db? -


the fallowing attribute defined on poco class.

public int total { get{ return sub_total_1 + sub_total_2; }} 

when new migration added attribute not created nor stored on table.

i tried add [column("total")] annotation without success.

is possible make attribute stored on db "cache" future queries?

thanks.

for ef able monitor property, needs have public (1) getter , setter.

for you're doing, unless need in database operations there, you're fine leaving readonly property in poco class. operation of adding 2 integers not @ performance worry, , slower push , pull database.

(1) setter can protected internal if want "read only" except database.

as example of how store value in database caching purposes, can this:

private int? total; public int total {         {         return total ?? sub_total_1 + sub_total_2;     }     protected internal set     {         total = value;     } } 

in example, new private total variable store in database. nullable if isn't retrieved database, default summation of sub_total_1 , sub_total_2. can find way around check in event sub properties have been updated after retrieved database, start you're doing.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -