Skip to content

Implementation for Find #11

@vongillern

Description

@vongillern

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions