本文整理汇总了C#中Tracker.SqlServer.CodeFirst.TrackerContext类的典型用法代码示例。如果您正苦于以下问题:C# TrackerContext类的具体用法?C# TrackerContext怎么用?C# TrackerContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TrackerContext类属于Tracker.SqlServer.CodeFirst命名空间,在下文中一共展示了TrackerContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FutureCountTest
public void FutureCountTest()
{
var db = new TrackerContext();
// build up queries
string emailDomain = "@battlestar.com";
var q1 = db.Users
.Where(p => p.EmailAddress.EndsWith(emailDomain))
.Future();
string search = "Earth";
var q2 = db.Tasks
.Where(t => t.Summary.Contains(search))
.FutureCount();
// should be 2 queries
//Assert.AreEqual(2, db.FutureQueries.Count);
// this triggers the loading of all the future queries
var users = q1.ToList();
Assert.IsNotNull(users);
// should be cleared at this point
//Assert.AreEqual(0, db.FutureQueries.Count);
// this should already be loaded
Assert.IsTrue(((IFutureQuery)q2).IsLoaded);
int count = q2;
Assert.AreNotEqual(count, 0);
}
示例2: Delete
public void Delete()
{
var db = new TrackerContext();
string emailDomain = "@test.com";
int count = db.Users
.Delete(u => u.EmailAddress.EndsWith(emailDomain));
}
示例3: TestCacheStrategy3
public void TestCacheStrategy3()
{
using (var db = new TrackerContext())
{
var role1 = CreateRole("Joe 1");
var role2 = CreateRole("Joe 2");
var role3 = CreateRole("Bob 3");
db.Roles.Add(role1);
db.Roles.Add(role2);
db.Roles.Add(role3);
db.SaveChanges();
db.Roles.Update(o => o.Name.StartsWith("J"), o => new Role { Description = "Updated joe" }, CacheStrategy.FullClean);
db.SaveChanges();
db.Roles.Local.Where(o => o.Id == role1.Id).Should().BeEmpty();
db.Roles.Local.Where(o => o.Id == role2.Id).Should().BeEmpty();
db.Roles.Local.Where(o => o.Id == role3.Id).Should().BeEmpty();
db.Roles.Where(o => o.Name.StartsWith("J") && o.Description != "Updated joe").Should().BeEmpty();
db.Roles.Where(o => o.Id == role3.Id && o.Description == role3.Name).Should().NotBeEmpty();
}
}
示例4: CreateLog2
public void CreateLog2()
{
AuditConfiguration.Default.IncludeRelationships = true;
AuditConfiguration.Default.LoadRelationships = true;
AuditConfiguration.Default.IsAuditable<Task>();
AuditConfiguration.Default.IsAuditable<User>();
var db = new TrackerContext();
var task2 = new Task()
{
Id = 1,
AssignedId = 1,
CreatedId = 1,
StatusId = 1,
PriorityId = 2,
Summary = "Summary: " + DateTime.Now.Ticks
};
db.Tasks.Add(task2);
var audit = db.BeginAudit();
var task = db.Tasks.Find(1);
Assert.IsNotNull(task);
task.PriorityId = 2;
task.StatusId = 2;
task.Summary = "Summary: " + DateTime.Now.Ticks;
var log = audit.CreateLog();
Assert.IsNotNull(log);
string xml = log.ToXml();
Assert.IsNotNull(xml);
}
示例5: TestCacheStrategy3
public void TestCacheStrategy3()
{
using (var db = new TrackerContext())
{
var role1 = CreateRole("Joe 1");
var role2 = CreateRole("Joe 2");
var role3 = CreateRole("Bob 3");
db.Roles.Add(role1);
db.Roles.Add(role2);
db.Roles.Add(role3);
db.SaveChanges();
db.Roles.Delete(o => o.Name.StartsWith("J"), CacheStrategy.FullClean);
db.SaveChanges();
db.Roles.Local.Where(o => o.Id == role1.Id).Should().BeEmpty();
db.Roles.Local.Where(o => o.Id == role2.Id).Should().BeEmpty();
db.Roles.Local.Where(o => o.Id == role3.Id).Should().BeEmpty();
db.Roles.Where(o => o.Name.StartsWith("J")).Should().BeEmpty();
db.Roles.Where(o => o.Id == role3.Id).Should().NotBeEmpty();
}
}
示例6: UpdateAsync
public async void UpdateAsync()
{
var db = new TrackerContext();
string emailDomain = "@test.com";
int count = await db.Users
.Where(u => u.EmailAddress.EndsWith(emailDomain))
.UpdateAsync(u => new User { IsApproved = false, LastActivityDate = DateTime.Now });
}
示例7: GetEntityMapAuditData
public void GetEntityMapAuditData()
{
var db = new TrackerContext();
var map = db.Audits.ToObjectQuery().GetEntityMap<AuditData>();
Assert.AreEqual("[dbo].[Audit]", map.TableName);
}
示例8: DeleteAsync
public async void DeleteAsync()
{
var db = new TrackerContext();
string emailDomain = "@test.com";
int count = await db.Users
.Where(u => u.EmailAddress.EndsWith(emailDomain))
.DeleteAsync();
}
示例9: FromCacheTest
public void FromCacheTest()
{
var db = new TrackerContext();
var roles = db.Roles.FromCache();
roles.Should().NotBeEmpty();
var roles2 = db.Roles.FromCache();
roles2.Should().NotBeEmpty();
}
示例10: FromCacheFirstOrDefaultTest
public void FromCacheFirstOrDefaultTest()
{
var db = new TrackerContext();
var role = db.Roles.FromCacheFirstOrDefault();
role.Should().NotBeNull();
var role2 = db.Roles.FromCacheFirstOrDefault();
role2.Should().NotBeNull();
}
示例11: DeleteWithExpressionContainingNullParameter
public void DeleteWithExpressionContainingNullParameter()
{
// This test verifies that the delete is processed correctly when the where expression uses a parameter with a null parameter
var db = new TrackerContext();
string emailDomain = "@test.com";
string optionalComparisonString = null;
int count = db.Users
.Delete(u => u.EmailAddress.EndsWith(emailDomain) && (string.IsNullOrEmpty(optionalComparisonString) || u.AvatarType == optionalComparisonString));
}
示例12: UpdateJoin
public void UpdateJoin()
{
var db = new TrackerContext();
string emailDomain = "@test.com";
string space = " ";
int count = db.Users.Update(
u => u.EmailAddress.EndsWith(emailDomain),
u => new User { LastName = u.FirstName + space + u.LastName });
}
示例13: UpdateAppend
public void UpdateAppend()
{
var db = new TrackerContext();
string emailDomain = "@test.com";
string newComment = " New Comment";
int count = db.Users
.Where(u => u.EmailAddress.EndsWith(emailDomain))
.Update(u => new User { LastName = u.LastName + newComment });
}
示例14: DeleteWhere
public void DeleteWhere()
{
var db = new TrackerContext();
string emailDomain = "@test.com";
//var user = db.Users.Select(u => new User { FirstName = u.FirstName, LastName = u.LastName });
int count = db.Users
.Where(u => u.EmailAddress.EndsWith(emailDomain))
.Delete();
}
示例15: UpdateWithExpressionContainingNullParameter
public void UpdateWithExpressionContainingNullParameter()
{
// This test verifies that the update is interpreted correctly when the where expression uses a parameter with a null parameter
var db = new TrackerContext();
string emailDomain = "@test.com";
string optionalComparisonString = null;
int count = db.Users.Update(
u => u.EmailAddress.EndsWith(emailDomain) && (string.IsNullOrEmpty(optionalComparisonString) || u.AvatarType == optionalComparisonString),
u => new User { IsApproved = false, LastActivityDate = DateTime.Now });
}