Eu precisei implementar algumas funcionalidades no model users
mas como vocês podem ver logo no início esta classe é gerada automaticamente pela Entity, então sempre que eu atualizar ou recriar o model as funcionalidades customizadas serão perdidas.
Exemplo de uma implementação customizada feito no model users
:
public string full_name
{
get
{
return this.first_name + ' ' + this.last_name;
}
}
Há alguma forma de sobrescrever o model para manter estas funcionalidades customizadas sem que sejam sobrescrevidas sempre que eu atualizar / recriar o 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: