1
I have a method that searches all the properties of my model, but I would not like to bring the entities that have as DataAnnotation
the attribute
NotMapped
.
Method
private IEnumerable<string> GetColumns()
{
return typeof(T)
.GetProperties()
.Where(e => e.Name != "Id" && !e.PropertyType.GetTypeInfo().IsGenericType)
.Select(e => e.Name);
}
Model:
using LaioMVC.Core.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
namespace LaioMVC.Core.Models
{
public class Usuario : EntityBase
{
[Required]
public string Nome { get; set; }
[Required]
public string Login { get; set; }
[Required]
public string Password { get; set; }
[NotMapped]
[Required]
public string ConfirmPassword { get; set; }
}
}
Something like that? https://answall.com/a/242745/101. Where does this one come from
T
?– Maniero
Yes that’s right, this T comes from my class owner of the Getcolumns() method which is generic. In this case it would be the type of my entity owner of the properties.
– Victor Laio
Possible duplicate of Check if there is value in the enumeration by the attribute and return its value
– novic