Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LINQ and C#: How to add a field, not mapped to a table column

Tags:

c#

linq

I load records from a database table. I need to add a field called "temp", which does not correspond to any table column. How can I add this field?

namespace mynamespace.Models
{
    public class alert
    {
        [Key]
        public int id { get; set; }
        public string text { get; set; }
        public string temp { get; set; } //<--- this generates error
    }
}

Thanks and regards.

like image 522
curious1 Avatar asked Sep 15 '25 08:09

curious1


1 Answers

Use the [NotMapped] attribute.

[NotMapped]
public string temp { get; set; }

Any property or class that has the NotMapped attribute will be excluded from database mapping.

like image 142
arao6 Avatar answered Sep 17 '25 22:09

arao6