You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public T Find(params object[] keyValues)
{
if (keyValues.Length != 1)
throw new Exception("not implemented");
var type = typeof(T);
var prop = type.GetProperty(type.Name + "Id");
var getter = prop.GetGetMethod();
var keyType = keyValues[0].GetType();
if (getter.ReturnType != keyType)
throw new Exception("mismatch keytype");
if (getter.ReturnType == typeof(Int32))
return this.FirstOrDefault(t => (int)getter.Invoke(t, null) == (int)keyValues[0]);
else if (getter.ReturnType == typeof(Guid))
return this.FirstOrDefault(t => (Guid)getter.Invoke(t, null) == (Guid)keyValues[0]);
else
throw new Exception("unknown keytype");
}
The text was updated successfully, but these errors were encountered:
I've got an implementation for Find that works assuming you're reasonable about your keys and primary key names.
My full file here: https://gist.github.com/vongillern/5ce21c06f5b15f30b63c
Just the find:
The text was updated successfully, but these errors were encountered: