private void InsertPostUsers(WfPostUserCollection postUsers) { using (TransactionScope scope = TransactionScopeFactory.Create()) { foreach (WfPostUser postUser in postUsers) { string ignoreFields = "UserID"; string sql = ORMapping.GetInsertSql(postUser, TSqlBuilder.Instance, ignoreFields); try { DbHelper.RunSql(sql, GetConnectionName()); } catch (System.Data.SqlClient.SqlException ex) { if (ex.ErrorCode != 2627) { throw; } } } scope.Complete(); } }
public void AddPostUsers(WfPost post, IEnumerable <IUser> users) { post.NullCheck("post"); users.NullCheck("users"); WfPostUserCollection postUsers = new WfPostUserCollection(); foreach (IUser user in users) { WfPostUser gu = new WfPostUser(); gu.PostID = post.PostID; gu.User = user; postUsers.Add(gu); } InsertPostUsers(postUsers); }