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

Returning types should be changed? #19

Closed
HybridSolutions opened this issue Feb 9, 2022 · 1 comment
Closed

Returning types should be changed? #19

HybridSolutions opened this issue Feb 9, 2022 · 1 comment

Comments

@HybridSolutions
Copy link

HybridSolutions commented Feb 9, 2022

HI once again,

I decided to open a new Issue since this is another matter.

The InsertAsync method returns an object[] type but I wonder why you decided to hide the default EntityEntry return type.
If the goal is to simplify and just return the primary key, then this could be done without hiding EntityEntry by using the following definition:

public async Task<(EntityEntry entity, object[] primaryKey)> InsertAsync<T>(T entity, CancellationToken cancellationToken = default)
           where T : class
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            EntityEntry<T> entityEntry = await _dbContext.Set<T>().AddAsync(entity, cancellationToken).ConfigureAwait(false);
            await _dbContext.SaveChangesAsync(cancellationToken).ConfigureAwait(false);

            object[] primaryKeyValue = entityEntry.Metadata.FindPrimaryKey().Properties.
                Select(p => entityEntry.Property(p.Name).CurrentValue).ToArray();

            return (entityEntry, primaryKeyValue);
        }

What do you think of this?

@TanvirArjel
Copy link
Owner

EntityEntry is nothing but the object they are passing for the insert operation. So returning to the same tracked entity does not make sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants