Validating partially filled objects The following classes are a simplification of an auto-generated code of an ORM (targeting Microsoft's Dynamics CRM):

public class Entity 
{
    public Dictionary&lt;string, object&gt; Fields { get; set;}
    public virtual T GetFieldValue&lt;T&gt;(string fieldName)
    {
         return (T)Fields[fieldName];
    }
    protected virtual void SetFieldValue(string fieldName, object value)
    {
         Fields[fieldName] = value;
    }
}
partial class Account : Entity
{
    public string Name
    get
    {
         return GetFieldValue&lt;string&gt;("Name");
    }
    set
    {
         SetFieldValue("Name", value);
    }
    public string Email
    get
    {
         return GetFieldValue&lt;string&gt;("Email");
    }
    set
    {
         SetFieldValue("Email", value);
    }
}


When an Entity's derived class is retrieved from the database, the base class Fields property is automatically assigned (again, this is not something in my control) with the selected fields.

I'd like a review of the following class, intended to validate "partially" filled objects:

public class EntitySubset&lt;T&gt; : Entity where T : Entity
{
    public EntitySubset(T subset)
    {
        foreach (var field in subset.Fields)
        {
            SetFieldValue(field.Key, field.Value);
        }
    }
    public override U GetFieldValue&lt;U&gt;(string fieldName)
    {
        if (!Fields.ContainsKey(fieldName))
        {
            throw new Exception($"{typeof(T).Name} must contain {fieldName} as a key!");
        }
        return base.GetFieldValue&lt;U&gt;(fieldName);
    }
}


an example usage:

private List&lt;Account&gt; GetSimiliarAccounts(EntitySubset&lt;Account&gt; targetAccount)
{
    var similarityFields = new[] { "Name", "Email" };
    var similiarAccounts = db.Where(account =&gt;
       similarityFields.All(f =&gt; 
          account.GetFieldValue&lt;object&gt;(f) == targetAccount.GetFieldValue&lt;object&gt;(f))
    ).ToList();
    return similiarAccounts;
}


so that if GetSimiliarAccounts is called as follows:

GetSimiliarAccounts(new EntitySubset&lt;Account&gt;(new Account { Email = "b" }));


then the output is:

System.Exception: 'Account must contain Name as a key!'


Note that EntitySubset&lt;T&gt; and its error messaging is intended for developers to "fail fast", namely: to quickly spot and fix bugs stemming from a partially filled object.

What do you think of EntitySubset&lt;T&gt; as a validation implementation?
Review

You should avoid hardcoded strings. Take advantage of nameof. Also, expression-bodied members (arrow notation) makes code cleaner to read.

public string Name
{
    get =&gt; GetFieldValue&lt;string&gt;(nameof(Name));
    set =&gt; SetFieldValue(nameof(Name), value);
}


EntitySubset&lt;T&gt;'s method GetFieldValue makes sure a clean (but technical) error message is thrown whenever an asked field is not available. 


public override U GetFieldValue&lt;U&gt;(string fieldName)
{
    if (!Fields.ContainsKey(fieldName))
    {
        throw new Exception($"{typeof(T).Name} must contain {fieldName} as a key!");
    }
    return base.GetFieldValue&lt;U&gt;(fieldName);
}



However, don't fallback to this method to perform business rules checks. The business layer should check that mandatory fields are filled in, before mapping the entities to the data layer.

You should also optimize ContainsKey and base.GetFieldValue. You don't want to perform 2 lookups here. Implement something like a TryGetFieldValue.