I needed to implement some functionality in the users
model but as you can see right at the beginning this class is automatically generated by Entity, so whenever I update or recreate the model the custom functionality will be lost.
Example of a custom implementation done in the users
model:
public string full_name
{
get
{
return this.first_name + ' ' + this.last_name;
}
}
Is there any way I can override the model to keep these features customized without being overwritten whenever I update / rebuild the model?
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace E_Learning.Models
{
using System;
using System.Collections.Generic;
using E_Learning.Helpers;
public partial class users
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public users()
{
this.updated_at = DateTime.Now;
this.created_at = DateTime.Now;
this.signatures = new HashSet<signatures>();
this.testimonials = new HashSet<testimonials>();
}
public int id { get; set; }
public string identity_ { get; set; }
public string first_name { get; set; }
public string last_name { get; set; }
public string email { get; set; }
public string telephone { get; set; }
public string password { get; set; }
public Nullable<System.DateTime> birthday { get; set; }
public Nullable<int> sexuality { get; set; }
public string remember_token { get; set; }
public System.DateTime updated_at { get; set; }
public System.DateTime created_at { get; set; }
public Nullable<byte> status { get; set; }
public string handle { get; set; }
public string setHandle ()
{
return Slugify.Make(this.first_name + ' ' + this.last_name);
}
public string full_name
{
get
{
return this.first_name + ' ' + this.last_name;
}
}
private Nullable<int> age
{
get
{
DateTime now = DateTime.Today;
if (this.birthday.HasValue)
{
DateTime birthday = DateTime.Parse(this.birthday.ToString());
int age = now.Year - birthday.Year;
if (now < birthday.AddYears(age))
age--;
return age;
}
return null;
}
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<signatures> signatures { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<testimonials> testimonials { get; set; }
}
}
Print: