Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7458221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T13:25:12+00:00 2026-05-29T13:25:12+00:00

I’d like to transform these Entity Framework’s properties into SQL Server’s computed columns. Is

  • 0

I’d like to transform these Entity Framework’s properties into SQL Server’s computed columns. Is it possible? All other properties specified are table fields.
Moreover, considering that I am using Code First, how I should specify the computed columns inside my model?

public enum Severity : int { INTIME = 0, B = 1, M = 2, A = 3, TIMEOUT = 4 };
public enum StatiTT : int { ND_INT = 1, ND_REP = 2, INT = 3, DI = 4, CH = 5, RV = 6, AN = 7 };
private const float TRESH_B = (float)0.5;
private const float TRESH_M = (float)0.3;
private const float TRESH_A = (float)0.2;

A)

 public int MinutiAllaScadenza
   {
       get
       {
           int mm = 0;
           DateTime Ora = DateTime.Now;

           mm = (DataObiettivo - Ora).Days*1440 + (DataObiettivo - Ora).Hours * 60 + (DataObiettivo - Ora).Minutes;

           if (StatoTicketID > (int)StatiTT.DI && mm < 0) mm = 10000000; 

           return mm;
       }
   }

B)

public int Sev 
   {
       get
       {
           int sev = 0; 
           float perctres = PercentualeTempoResiduo; 

           if (StatoTicketID < (int)StatiTT.CH)
           {
               if (MinutiAllaScadenza < 0) { sev = (int)Severity.TIMEOUT; return sev; }
               if (perctres < TRESH_A) { sev = (int)Severity.A; return sev; }
               if (perctres < TRESH_M) { sev = (int)Severity.M; return sev; }
               if (perctres < TRESH_B) { sev = (int)Severity.B; return sev; }
           }
           return sev;
       }
   }

C)

public float PercentualeTempoResiduo
   {
       get
       {

           if (StatoTicketID > (int)StatiTT.DI) return 999;

           float perc = 0;
           float mm2scad = (float)MinutiAllaScadenza;
           float mmtot = (float)TempoTotaleInizio_Obiettivo;

           if (MinutiAllaScadenza > 0)

               perc = (float)1 - (mmtot-mm2scad) / mmtot;

           return perc;
       }
   }

D)

   public string Alert
   {
       get
       {
           string alert = "";
           float perctres = PercentualeTempoResiduo; 

           if (StatoTicketID < (int)StatiTT.CH) {
               if (perctres < TRESH_A) { alert = "A"; return alert; }
               if (perctres < TRESH_M) { alert = "M"; return alert; }
               if (perctres < TRESH_B) { alert = "B"; return alert; }
           }
           return alert;
       }
   }

Thank you very much!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T13:25:13+00:00Added an answer on May 29, 2026 at 1:25 pm

    The answer to your main question is yes, these C# routines can be converted to computed columns. But there’s one condition: the relevant information needed to compute the result must be found in the table itself.

    For your Alert property, here’s how your computed column would look:

    alter table <TBLNAME> add <COLNAME>  AS (
      case 
        when StatoTicketID < (int)StatiTT.CH AND perctres < .2 then 'A'
        when StatoTicketID < (int)StatiTT.CH AND perctres < .3 then 'M'
        when StatoTicketID < (int)StatiTT.CH AND perctres < .5 then 'B'
        else ''
      end)
    

    If your computed result needs to use information from other tables then consider binding EF to a view for reading and then using plain EF objects for your write operations.

    As for code first, you cannot write a computed column in C# and expect EF to translate that into a SQLServer computed column for you. Write the computed column in the DB after you’ve done your model first generating and then go back and wire it into your EF object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a text area in my form which accepts all possible characters from
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
this is what i have right now Drawing an RSS feed into the php,
I would like to run a str_replace or preg_replace which looks for certain words
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.