Why does the Execution Plan include a user-defined function call for a computed column that is persisted?

The reason is that the query optimizer does not do a very good job at costing user-defined functions. It decides, in some cases, that it would be cheaper to completely re-evaluate the function for each row, rather than incur the disk reads that might be necessary otherwise. SQL Server’s costing model does not inspect the … Read more

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