Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetByKey needs to be reworked to not need explicit table names #342

Closed
Grauenwolf opened this issue Jan 31, 2020 · 2 comments
Closed

GetByKey needs to be reworked to not need explicit table names #342

Grauenwolf opened this issue Jan 31, 2020 · 2 comments

Comments

@Grauenwolf
Copy link
Collaborator

Here is the current syntax

m_DataSource.GetByKey("HR.EmployeeClassification", employeeClassificationKey).ToObject<EmployeeClassification>().Execute();

Notice how the table name is mentioned twice, once directly and once in the materializer.

We want this:

m_DataSource.GetByKey<EmployeeClassification>(employeeClassificationKey).ToObject().Execute();
@Grauenwolf
Copy link
Collaborator Author

We can't completely generalize it, but this will get us close:

    /// <summary>
    /// Gets a record by its primary key.
    /// </summary>
    /// <typeparam name="TObject">The type of the object.</typeparam>
    /// <param name="key">The key.</param>
    /// <returns></returns>
    /// <remarks>This only works on tables that have a scalar primary key.</remarks>
    ISingleRowDbCommandBuilder GetByKey<TObject>(Guid key)
        where TObject : class;

    /// <summary>
    /// Gets a record by its primary key.
    /// </summary>
    /// <typeparam name="TObject">The type of the object.</typeparam>
    /// <param name="key">The key.</param>
    /// <returns></returns>
    /// <remarks>This only works on tables that have a scalar primary key.</remarks>
    ISingleRowDbCommandBuilder GetByKey<TObject>(long key)
        where TObject : class;

    /// <summary>
    /// Gets a record by its primary key.
    /// </summary>
    /// <typeparam name="TObject">The type of the object.</typeparam>
    /// <param name="key">The key.</param>
    /// <returns></returns>
    /// <remarks>This only works on tables that have a scalar primary key.</remarks>
    ISingleRowDbCommandBuilder GetByKey<TObject>(int key)
        where TObject : class;

    /// <summary>
    /// Gets a record by its primary key.
    /// </summary>
    /// <typeparam name="TObject">The type of the object.</typeparam>
    /// <param name="key">The key.</param>
    /// <returns></returns>
    ISingleRowDbCommandBuilder GetByKey<TObject>(string key)
        where TObject : class;

And for any oddball scenarios

    /// <summary>
    /// Gets a record by its primary key.
    /// </summary>
    /// <typeparam name="TObject">The type of the object.</typeparam>
    /// <typeparam name="TKey"></typeparam>
    /// <param name="key">The key.</param>
    /// <returns></returns>
    /// <remarks>This only works on tables that have a scalar primary key.</remarks>
    ISingleRowDbCommandBuilder GetByKey<TObject, TKey>(TKey key)
        where TObject : class
        where TKey : struct;

@Grauenwolf Grauenwolf changed the title GetByKey needs to be reworked GetByKey/DeleteByKey needs to be reworked to not need explicit table names Jan 31, 2020
@Grauenwolf Grauenwolf changed the title GetByKey/DeleteByKey needs to be reworked to not need explicit table names GetByKey/DeleteByKey/DeleteWithFilter needs to be reworked to not need explicit table names Jan 31, 2020
@Grauenwolf Grauenwolf changed the title GetByKey/DeleteByKey/DeleteWithFilter needs to be reworked to not need explicit table names GetByKey needs to be reworked to not need explicit table names Jan 31, 2020
@Grauenwolf
Copy link
Collaborator Author

See also #348

@Grauenwolf Grauenwolf self-assigned this Feb 9, 2020
Grauenwolf added a commit that referenced this issue Feb 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant