1

I have the following model:

[Key]
public string Id { get; set; }
    
[IsSearchable]
public string Code{ get; set; }
    
[IsSearchable]
public string Name { get; set; }
    
[IsSearchable]
public string Address { get; set; }
    
[IsSearchable]
public string PostCode { get; set; }  
        
[IsFilterable]
public int? Setting{ get; set; }
    
[IsFilterable, IsSortable]
public Location Location { get; set; }

I am comparing a model in a database with the above one, and want to check that the database model has the same attributes. Is there any way to find out the specific number of attributes without having to hard code them in? For example, this is the method I've written to check:

private bool CheckAttributeEquality(List<PropertyInfo>searchableAttributeProperties,
                   List<PropertyInfo> filterableAttributeProperties,
                   List<PropertyInfo> sortableAttributeProperties,
                   List<PropertyInfo> keyAttributeProperties)
{
    if (searchableAttributeProperties.Count == 4 &&
        filterableAttributeProperties.Count == 2 &&
        sortableAttributeProperties.Count == 1 &&
        keyAttributeProperties.Count == 1)
    {
        return true;
    }

    return false;
}

However I don't want to hard code these in, I want to make sure they match the attributes on my model? Can anyone help?

Sh.Imran
  • 1,035
  • 7
  • 13
Jordan1993
  • 864
  • 1
  • 10
  • 28
  • What is "model in a database" ? I guess you just want to enumerate properties and for each property enumerate its attributes. See [this answer](https://stackoverflow.com/a/6637710/1997232). – Sinatr Jul 21 '20 at 14:06
  • This is not what you are asking, but it could be helpful - https://www.entityframeworktutorial.net/code-first/code-first-from-existing-database.aspx, you could generate model classes from db models. – WhiteRom Jul 31 '20 at 14:10

0 Answers0