コード例 #1
0
        public async Task <User> GetUserById(Guid id)
        {
            var query = $@"select {_userMap.ForAllProps("u")}, {_personMap.ForAllProps("p")}
                            from {_userMap.TableName} as u
                            left join {_personMap.TableName} as p
                                on u.{_userMap.ColumnName(c => c.Id)} = p.{_personMap.ColumnName(c => c.UserId)}
                            where u.{_userMap.ColumnName(c => c.Id)} = '{id}'";

            User user = null;

            var result = await GetAwaitableDataCollectionLoader <User, Person, User>(query, (u, p) =>
            {
                if (u != null && user == null)
                {
                    user = u;
                }
                if (p != null)
                {
                    user.Persons.Add(p);
                }
                return(u);
            });

            return(result.FirstOrDefault());
        }