本文整理汇总了C#中Session.Update方法的典型用法代码示例。如果您正苦于以下问题:C# Session.Update方法的具体用法?C# Session.Update怎么用?C# Session.Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Session
的用法示例。
在下文中一共展示了Session.Update方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateName
/// <summary>
/// 用户更新用户名
/// </summary>
/// <param name="session"></param>
/// <param name="user"></param>
/// <param name="newName"></param>
/// <param name="currentAccountNo"></param>
/// <returns></returns>
public static bool UpdateName(Session session, User user, string newName, string currentAccountNo)
{
if (string.IsNullOrEmpty(newName)) throw new ArgumentNullException("newName");
if (newName.Equals(user.Name)) return true;
var account = session.Load<Account>(m => m.Name.Equals(user.Name));
if(account == null) throw new ArgumentException(string.Format("用户{0}不存在", user.Name), "user");
account.Name = newName;
user.Name = newName;
return session.Update(user) &&
session.Update(account) &&
user.Deactive(session, currentAccountNo);
}
示例2: UpdateObjectDeltaThrowsObjectDisposedExceptionIfDisposed
public void UpdateObjectDeltaThrowsObjectDisposedExceptionIfDisposed()
{
var session = new Session(
ConnectionScope.PerTransaction,
new Mock<ISqlDialect>().Object,
new Mock<IDbDriver>().Object,
new IDeleteListener[0],
new IInsertListener[0],
new IUpdateListener[0]);
using (session)
{
}
Assert.Throws<ObjectDisposedException>(() => session.Update(new ObjectDelta(typeof(Customer), 1234)));
}
示例3: UpdateObjectDeltaThrowsMicroLiteExceptionIfItContainsNoChanges
public void UpdateObjectDeltaThrowsMicroLiteExceptionIfItContainsNoChanges()
{
var objectDelta = new ObjectDelta(typeof(Customer), 1234);
var session = new Session(
ConnectionScope.PerTransaction,
new Mock<ISqlDialect>().Object,
new Mock<IDbDriver>().Object,
new IDeleteListener[0],
new IInsertListener[0],
new IUpdateListener[0]);
var exception = Assert.Throws<MicroLiteException>(() => session.Update(objectDelta));
Assert.Equal(ExceptionMessages.ObjectDelta_MustContainAtLeastOneChange, exception.Message);
}
示例4: UpdateObjectDeltaReturnsTrueIfRecordUpdated
public void UpdateObjectDeltaReturnsTrueIfRecordUpdated()
{
var objectDelta = new ObjectDelta(typeof(Customer), 1234);
objectDelta.AddChange("Name", "Fred Flintstone");
var mockSqlDialect = new Mock<ISqlDialect>();
mockSqlDialect.Setup(x => x.BuildUpdateSqlQuery(objectDelta)).Returns(new SqlQuery(""));
var mockCommand = new Mock<IDbCommand>();
mockCommand.Setup(x => x.ExecuteNonQuery()).Returns(1);
var mockConnection = new Mock<IDbConnection>();
mockConnection.Setup(x => x.CreateCommand()).Returns(mockCommand.Object);
var mockDbDriver = new Mock<IDbDriver>();
mockDbDriver.Setup(x => x.CreateConnection()).Returns(mockConnection.Object);
var session = new Session(
ConnectionScope.PerTransaction,
mockSqlDialect.Object,
mockDbDriver.Object,
new IDeleteListener[0],
new IInsertListener[0],
new IUpdateListener[0]);
Assert.True(session.Update(objectDelta));
mockDbDriver.VerifyAll();
mockCommand.VerifyAll();
}
示例5: UpdateInstanceThrowsMicroLiteExceptionIfIdentifierNotSet
public void UpdateInstanceThrowsMicroLiteExceptionIfIdentifierNotSet()
{
var customer = new Customer
{
Id = 0
};
var mockDbDriver = new Mock<IDbDriver>();
mockDbDriver.Setup(x => x.CreateConnection()).Returns(new Mock<IDbConnection>().Object);
var session = new Session(
ConnectionScope.PerTransaction,
new Mock<ISqlDialect>().Object,
mockDbDriver.Object,
new IDeleteListener[0],
new IInsertListener[0],
new IUpdateListener[0]);
var exception = Assert.Throws<MicroLiteException>(() => session.Update(customer));
Assert.Equal(ExceptionMessages.Session_IdentifierNotSetForUpdate, exception.Message);
}
示例6: UpdateObjectDeltaReturnsFalseIfNoRecordUpdated
public void UpdateObjectDeltaReturnsFalseIfNoRecordUpdated()
{
var objectDelta = new ObjectDelta(typeof(Customer), 1234);
objectDelta.AddChange("Name", "Fred Flintstone");
var mockCommand = new Mock<IDbCommand>();
mockCommand.Setup(x => x.ExecuteNonQuery()).Returns(0);
mockCommand.As<IDisposable>().Setup(x => x.Dispose());
var mockSqlDialect = new Mock<ISqlDialect>();
mockSqlDialect.Setup(x => x.BuildUpdateSqlQuery(objectDelta)).Returns(new SqlQuery(""));
var mockDbDriver = new Mock<IDbDriver>();
mockDbDriver.Setup(x => x.GetConnection(ConnectionScope.PerTransaction)).Returns(new Mock<IDbConnection>().Object);
mockDbDriver.Setup(x => x.BuildCommand(It.IsNotNull<SqlQuery>())).Returns(mockCommand.Object);
var session = new Session(
ConnectionScope.PerTransaction,
mockSqlDialect.Object,
mockDbDriver.Object,
new IListener[0]);
Assert.False(session.Update(objectDelta));
mockDbDriver.VerifyAll();
mockCommand.VerifyAll();
}
示例7: SaveNavigation
private static long SaveNavigation(Session session, long navId, string moduelUrl)
{
var nav = session.Load<Navigation>(navId);
if (nav == null) throw new ArgumentNullException("navId");
nav.Url = moduelUrl;
if (session.Update(nav)) { return nav.Id; }
throw new Exception(string.Format("保存导航失败:Id - {0}, Name - {1}", nav.Id, nav.Name));
}
示例8: UpdateInstanceThrowsArgumentNullExceptionForNullInstance
public void UpdateInstanceThrowsArgumentNullExceptionForNullInstance()
{
var session = new Session(
ConnectionScope.PerTransaction,
new Mock<ISqlDialect>().Object,
new Mock<IDbDriver>().Object,
new IDeleteListener[0],
new IInsertListener[0],
new IUpdateListener[0]);
var exception = Assert.Throws<ArgumentNullException>(() => session.Update((Customer)null));
Assert.Equal("instance", exception.ParamName);
}
示例9: DeactiveAccount
public bool DeactiveAccount(Session session, string currentAccountNo)
{
var account = session.Load<Account>(m => m.Name.Equals(Name));
if (account == null)
{
account = new Account();
account.Name = Name;
account.Password = Guid.NewGuid().ToString();
account.Status = Account.Inactive;
account.CreatedAt = DateTime.Now;
account.CreatedBy = currentAccountNo;
return session.Create(account);
}
account.Status = Account.Inactive;
account.UpdatedAt = DateTime.Now;
account.UpdatedBy = currentAccountNo;
return session.Update(account);
}
示例10: DeactiveAccount
private bool DeactiveAccount(Session session, string currentAccountNo)
{
var account = session.Load<Account>(m => m.Name.Equals(Code));
if (account == null)
{
account = new Account
{
Name = Code,
Password = Guid.NewGuid().ToString(),
Status = Account.Inactive,
CreatedAt = DateTime.Now,
CreatedBy = currentAccountNo
};
return session.Create(account);
}
account.Flag = null;
account.Status = Account.Inactive;
account.UpdatedAt = DateTime.Now;
account.UpdatedBy = currentAccountNo;
return session.Update(account);
}
示例11: ActiveUser
private bool ActiveUser(Session session, string currentAccountNo)
{
IsActive = true;
UpdatedAt = DateTime.Now;
UpdatedBy = currentAccountNo;
return session.Update(this);
}
示例12: UpdateInstanceBuildsAndExecutesQuery
public void UpdateInstanceBuildsAndExecutesQuery()
{
var customer = new Customer
{
Id = 187224
};
var rowsAffected = 1;
var mockSqlDialect = new Mock<ISqlDialect>();
mockSqlDialect.Setup(x => x.BuildUpdateSqlQuery(It.IsNotNull<IObjectInfo>(), customer)).Returns(new SqlQuery(""));
var mockCommand = new Mock<IDbCommand>();
mockCommand.Setup(x => x.ExecuteNonQuery()).Returns(rowsAffected);
var mockConnection = new Mock<IDbConnection>();
mockConnection.Setup(x => x.CreateCommand()).Returns(mockCommand.Object);
var mockDbDriver = new Mock<IDbDriver>();
mockDbDriver.Setup(x => x.CreateConnection()).Returns(mockConnection.Object);
var session = new Session(
ConnectionScope.PerTransaction,
mockSqlDialect.Object,
mockDbDriver.Object,
new SessionListeners());
session.Update(customer);
mockSqlDialect.VerifyAll();
mockDbDriver.VerifyAll();
mockCommand.VerifyAll();
}
示例13: UpdateObjectDeltaThrowsArgumentNullExceptionForNullObjectDelta
public void UpdateObjectDeltaThrowsArgumentNullExceptionForNullObjectDelta()
{
var session = new Session(
ConnectionScope.PerTransaction,
new Mock<ISqlDialect>().Object,
new Mock<IDbDriver>().Object,
new SessionListeners());
var exception = Assert.Throws<ArgumentNullException>(() => session.Update((ObjectDelta)null));
Assert.Equal("objectDelta", exception.ParamName);
}
示例14: UpdateInstanceThrowsObjectDisposedExceptionIfDisposed
public void UpdateInstanceThrowsObjectDisposedExceptionIfDisposed()
{
var session = new Session(
ConnectionScope.PerTransaction,
new Mock<ISqlDialect>().Object,
new Mock<IDbDriver>().Object,
new SessionListeners());
using (session)
{
}
Assert.Throws<ObjectDisposedException>(() => session.Update(new Customer()));
}
示例15: UpdateInstanceInvokesListeners
public void UpdateInstanceInvokesListeners()
{
var customer = new Customer
{
Id = 187224
};
var rowsAffected = 1;
var mockSqlDialect = new Mock<ISqlDialect>();
mockSqlDialect.Setup(x => x.BuildUpdateSqlQuery(It.IsNotNull<IObjectInfo>(), customer)).Returns(new SqlQuery(""));
var mockCommand = new Mock<IDbCommand>();
mockCommand.Setup(x => x.ExecuteNonQuery()).Returns(rowsAffected);
var mockConnection = new Mock<IDbConnection>();
mockConnection.Setup(x => x.CreateCommand()).Returns(mockCommand.Object);
var mockDbDriver = new Mock<IDbDriver>();
mockDbDriver.Setup(x => x.CreateConnection()).Returns(mockConnection.Object);
int counter = 0;
var mockListener1 = new Mock<IUpdateListener>();
mockListener1.Setup(x => x.AfterUpdate(customer, 1)).Callback(() => Assert.Equal(4, ++counter));
mockListener1.Setup(x => x.BeforeUpdate(customer)).Callback(() => Assert.Equal(1, ++counter));
var mockListener2 = new Mock<IUpdateListener>();
mockListener2.Setup(x => x.AfterUpdate(customer, 1)).Callback(() => Assert.Equal(3, ++counter));
mockListener2.Setup(x => x.BeforeUpdate(customer)).Callback(() => Assert.Equal(2, ++counter));
var session = new Session(
ConnectionScope.PerTransaction,
mockSqlDialect.Object,
mockDbDriver.Object,
new IDeleteListener[0],
new IInsertListener[0],
new[] { mockListener1.Object, mockListener2.Object });
session.Update(customer);
mockListener1.VerifyAll();
mockListener2.VerifyAll();
}