-
Notifications
You must be signed in to change notification settings - Fork 23
Open
Description
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:
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");
}
Metadata
Metadata
Assignees
Labels
No labels