コード例 #1
0
        private void AddProfile(string userId, Profile profile)
        {
            var sql = $@"INSERT INTO Profiles (Age, Sex, Location)
                        VALUES (@{nameof(Profile.Age)}, @{nameof(Profile.Sex)}, @{nameof(Profile.Location)});
                        INSERT INTO UserProfileMap (UserId, ProfileId)
                        VALUES (@{nameof(userId)}, LAST_INSERT_ID());";

            UnitOfWork.AddOperation(profile, async connection =>
                                    await connection.ExecuteAsync(sql, new
            {
                profile.Age,
                profile.Sex,
                profile.Location,
                userId
            }));
        }
コード例 #2
0
        private void UpdateProfile(Profile profile)
        {
            var sql = $@"UPDATE Profiles SET
                            Age = @{nameof(Profile.Age)},
                            Sex = @{nameof(Profile.Sex)},
                            Location = @{nameof(Profile.Location)}
                        WHERE Profiles.Id = @{nameof(profile.Id)}";

            UnitOfWork.AddOperation(profile, async connection =>
                                    await connection.ExecuteAsync(sql, new
            {
                profile.Age,
                profile.Sex,
                profile.Location,
                profile.Id
            }));
        }