Calculated column in EF Code First

You can create computed columns in your database tables. In the EF model you just annotate the corresponding properties with the DatabaseGenerated attribute: [DatabaseGenerated(DatabaseGeneratedOption.Computed)] public double Summ { get; private set; } Or with fluent mapping: modelBuilder.Entity<Income>().Property(t => t.Summ) .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed) As suggested by Matija Grcic and in a comment, it’s a good idea to make … Read more

Sql Server deterministic user-defined function

You just need to create it with schemabinding. SQL Server will then verify whether or not it meets the criteria to be considered as deterministic (which it does as it doesn’t access any external tables or use non deterministic functions such as getdate()). You can verify that it worked with SELECT OBJECTPROPERTY(OBJECT_ID(‘[dbo].[FullNameLastFirst]’), ‘IsDeterministic’) Adding the … Read more

PostgreSQL: using a calculated column in the same query

You need to wrap the SELECT statement into a derived table in order to be able to access the column alias: select cost1, quantity_1, cost_2, quantity_2 total_1 + total_2 as total_3 from ( select cost_1, quantity_1, cost_2, quantity_2, (cost_1 * quantity_1) as total_1, (cost_2 * quantity_2) as total_2 from data ) t There won’t be … Read more

How can one work fully generically in data.table in R with column names in variables

Problem you are describing is not strictly related to data.table. Complex queries cannot be easily translated to code that machine can parse, thus we are not able to escape complexity in writing a query for complex operations. You can try to imagine how to programmatically construct a query for the following data.table query using dplyr … Read more