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

NullReferenceException may be thrown #86

Open
murashik opened this issue Mar 27, 2019 · 0 comments
Open

NullReferenceException may be thrown #86

murashik opened this issue Mar 27, 2019 · 0 comments

Comments

@murashik
Copy link

if _unitOfWork is null then here can crash: transaction: _unitOfWork.Transaction. I'm right?

//namespace Identity.Dapper.Repositories
var selectFunction = new Func<DbConnection, Task<TUser>>(async x =>
                {
                    var dynamicParameters = new DynamicParameters();
                    dynamicParameters.Add("Email", email);

                    var query = _queryFactory.GetQuery<SelectUserByEmailQuery>();

                    var userDictionary = new Dictionary<TKey, TUser>();
                    var result = await x.QueryAsync<TUser, TUserRole, TUser>(sql: query,
                                                                             param: dynamicParameters,
                                                                             transaction: _unitOfWork.Transaction,
                                                                             map: UserRoleMapping(userDictionary),
                                                                             splitOn: "UserId");

                    if (userDictionary.Count > 0)
                        return userDictionary.FirstOrDefault().Value;

                    return result.FirstOrDefault();
                });

                DbConnection conn = null;
                if (_unitOfWork?.Connection == null)
                {
                    using (conn = _connectionProvider.Create())
                    {
                        await conn.OpenAsync();

                        return await selectFunction(conn);
                    }
                }
@murashik murashik changed the title NullReferenceException exception may be thrown NullReferenceException may be thrown Mar 27, 2019
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

1 participant