本文整理汇总了C#中System.Data.Entity.TestModels.ArubaModel.ArubaContext类的典型用法代码示例。如果您正苦于以下问题:C# ArubaContext类的具体用法?C# ArubaContext怎么用?C# ArubaContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ArubaContext类属于System.Data.Entity.TestModels.ArubaModel命名空间,在下文中一共展示了ArubaContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SelectMany_with_DefaultIfEmpty_translates_into_left_outer_join
public void SelectMany_with_DefaultIfEmpty_translates_into_left_outer_join()
{
using (var context = new ArubaContext())
{
var expectedSql =
@"SELECT
[Extent1].[Id] AS [Id],
[Extent2].[Id] AS [Id1],
[Extent2].[Name] AS [Name],
[Extent2].[Deleted] AS [Deleted],
[Extent2].[TaskInfo_Passed] AS [TaskInfo_Passed],
[Extent2].[TaskInfo_Failed] AS [TaskInfo_Failed],
[Extent2].[TaskInfo_Investigates] AS [TaskInfo_Investigates],
[Extent2].[TaskInfo_Improvements] AS [TaskInfo_Improvements],
[Extent2].[ArubaRun_Id] AS [ArubaRun_Id]
FROM [dbo].[ArubaRuns] AS [Extent1]
LEFT OUTER JOIN [dbo].[ArubaTasks] AS [Extent2] ON [Extent1].[Id] = [Extent2].[ArubaRun_Id]";
var query = context.Runs.SelectMany(c => c.Tasks.DefaultIfEmpty());
QueryTestHelpers.VerifyDbQuery(query, expectedSql);
// verify that owners that have empty collecion of bugs are projected as nulls
var results = query.ToList();
var ownersWithoutBugsCount = context.Runs.Count(o => !o.Tasks.Any());
Assert.Equal(ownersWithoutBugsCount, results.Count(r => r == null));
}
}
示例2: DefaultIfEmpty_with_non_null_default
public void DefaultIfEmpty_with_non_null_default()
{
using (var context = new ArubaContext())
{
var expectedSql =
@"SELECT
[Extent1].[Id] AS [Id],
[Extent1].[FirstName] AS [FirstName],
[Extent1].[LastName] AS [LastName],
[Extent1].[Alias] AS [Alias],
CASE WHEN ([Join1].[Id1] IS NULL) THEN 0 ELSE [Join1].[Id1] END AS [C1]
FROM [dbo].[ArubaOwners] AS [Extent1]
LEFT OUTER JOIN (SELECT [Extent2].[Id] AS [Id1], [Extent2].[ArubaOwner_Id] AS [ArubaOwner_Id]
FROM [dbo].[Bugs1] AS [Extent2]
INNER JOIN [dbo].[Bugs2] AS [Extent3] ON [Extent2].[Id] = [Extent3].[Id] ) AS [Join1] ON ([Extent1].[Id] = [Join1].[ArubaOwner_Id]) AND (1 = [Join1].[Id1])";
var query = context.Owners.SelectMany(c => c.Bugs.Where(b => b.Id == 1).Select(b => b.Id).DefaultIfEmpty(), (o, b) => new { o, b });
QueryTestHelpers.VerifyDbQuery(query, expectedSql);
// verify that all owners are projected
// verify that the only bug that is non 0 has Id = 1
var results = query.ToList();
var ownersCount = context.Owners.Count();
Assert.Equal(ownersCount, results.Select(r => r.o.Id).Distinct().Count());
for (int i = 0; i < ownersCount; i++)
{
var bugId = results[i].b;
Assert.True(bugId == 0 || bugId == 1);
}
}
}
示例3: GeometryPointsWithinPolygon
public void GeometryPointsWithinPolygon()
{
var query = @"
select value
g.c32_geometry
from
ArubaContext.AllTypes as g
where
Edm.SpatialWithin(
g.c32_geometry,
GeometryFromText(""MULTILINESTRING ((10 20, 15 20, 15 25, 10 25, 10 20), (12 22, 13 22, 13 23, 12 23, 12 22))"", 32768))";
// verifying that the points returned are within the specified polygon
using (var db = new ArubaContext())
using (var reader = QueryTestHelpers.EntityCommandSetup(db, query, "STWithin"))
{
var shape = DbGeometry.MultiLineFromText(
"MULTILINESTRING ((10 20, 15 20, 15 25, 10 25, 10 20), (12 22, 13 22, 13 23, 12 23, 12 22))", 32768);
VerifyValueCondition(reader, o =>
{
var g = (DbGeometry)o;
return DbSpatialServices.Default.Within(g, shape);
});
}
}
示例4: TruncationTests
public TruncationTests()
{
using (var context = new ArubaContext())
{
context.Database.Initialize(force: false);
}
}
示例5: String_StartsWith_properly_translated_to_function
public void String_StartsWith_properly_translated_to_function()
{
using (var context = new ArubaContext())
{
var query = context.Owners.Select(o => o.LastName.StartsWith("Name"));
Assert.Contains("LIKE N'NAME%'", query.ToString().ToUpperInvariant());
}
}
示例6: DateTime_UtcNow_properly_translated_to_function
public void DateTime_UtcNow_properly_translated_to_function()
{
using (var context = new ArubaContext())
{
var query = context.Owners.Select(o => DateTime.UtcNow);
Assert.Contains("SYSUTCDATETIME", query.ToString().ToUpperInvariant());
}
}
示例7: String_Length_properly_translated_to_function
public void String_Length_properly_translated_to_function()
{
using (var context = new ArubaContext())
{
var query = context.Owners.Select(o => o.LastName.Length);
Assert.Contains("LEN", query.ToString().ToUpperInvariant());
}
}
示例8: String_Concat_translated_properly_to_plus_operator
public void String_Concat_translated_properly_to_plus_operator()
{
using (var context = new ArubaContext())
{
var query = context.Owners.Select(o => string.Concat(o.LastName, o.FirstName));
Assert.True(query.ToString().Contains("+"));
}
}
示例9: DateTimeOffest_Day_properly_translated_to_function
public void DateTimeOffest_Day_properly_translated_to_function()
{
using (var context = new ArubaContext())
{
var query = context.AllTypes.Select(a => a.c30_datetimeoffset.Day);
Assert.Contains("DATEPART", query.ToString().ToUpperInvariant());
Assert.Contains("DAY", query.ToString().ToUpperInvariant());
}
}
示例10: Include_one_to_one_relationship
public void Include_one_to_one_relationship()
{
using (var context = new ArubaContext())
{
((IObjectContextAdapter)context).ObjectContext.ContextOptions.LazyLoadingEnabled = false;
var query = context.Owners.Include(o => o.OwnedRun);
var results = query.ToList();
var runsForOwners = context.Owners.Select(r => r.OwnedRun).ToList();
Enumerable.SequenceEqual(runsForOwners, results.Select(r => r.OwnedRun));
}
}
示例11: IndexOf_properly_translated_to_function
public void IndexOf_properly_translated_to_function()
{
using (var context = new ArubaContext())
{
var query = context.Owners.Select(o => o.LastName.IndexOf("N"));
// translated to charindex() - 1
Assert.True(query.ToString().ToLowerInvariant().Contains("charindex"));
Assert.Contains("CHARINDEX", query.ToString().ToUpperInvariant());
Assert.True(query.ToString().Contains("- 1"));
}
}
示例12: IsNullOrEmpty_translated_properly_to_expression
public void IsNullOrEmpty_translated_properly_to_expression()
{
using (var context = new ArubaContext())
{
var expectedSql =
@"SELECT
CASE WHEN (([Extent1].[LastName] IS NULL) OR (( CAST(LEN([Extent1].[LastName]) AS int)) = 0)) THEN cast(1 as bit) WHEN ( NOT (([Extent1].[LastName] IS NULL) OR (( CAST(LEN([Extent1].[LastName]) AS int)) = 0))) THEN cast(0 as bit) END AS [C1]
FROM [dbo].[ArubaOwners] AS [Extent1]";
var query = context.Owners.Select(o => string.IsNullOrEmpty(o.LastName));
QueryTestHelpers.VerifyDbQuery(query, expectedSql);
}
}
示例13: Can_materialize_null_complex_type
public void Can_materialize_null_complex_type()
{
using (var context = new ArubaContext())
{
var query = context.Runs.Select(r => r.Tasks.Where(t => t.Id < 0).Select(t => t.TaskInfo).FirstOrDefault());
var results = query.ToList();
Assert.IsType<List<ArubaTaskInfo>>(results);
foreach (var result in results)
{
Assert.Null(result);
}
}
}
示例14: OrderBy_ThenBy_lifted_above_type_filter
public void OrderBy_ThenBy_lifted_above_type_filter()
{
using (var context = new ArubaContext())
{
var query = context.Configs.OrderByDescending(p => p.Arch).ThenBy(p => p.Id).OfType<ArubaMachineConfig>();
var baseline = context.Configs.OfType<ArubaMachineConfig>().OrderByDescending(p => p.Arch).ThenBy(p => p.Id);
Assert.Equal(baseline.ToString(), query.ToString());
var results = query.ToList();
var expected = context.Configs.ToList().OrderByDescending(p => p.Arch).ThenBy(p => p.Id).OfType<ArubaMachineConfig>().ToList();
QueryTestHelpers.VerifyQueryResult(expected, results, (o, i) => o.Id == i.Id);
}
}
示例15: OrderBy_ThenBy_Skip_lifted_above_projection
public void OrderBy_ThenBy_Skip_lifted_above_projection()
{
using (var context = new ArubaContext())
{
var query = context.Owners.OrderByDescending(p => p.FirstName).ThenBy(p => p.Id).Skip(5).Select(p => new { p.FirstName, p.Id, Foo = p.Id * 5 });
var baseline = context.Owners.Select(p => new { p.FirstName, p.Id, Foo = p.Id * 5 }).OrderByDescending(p => p.FirstName).ThenBy(p => p.Id).Skip(5);
Assert.Equal(baseline.ToString(), query.ToString());
var results = query.ToList();
var expected = context.Owners.ToList().OrderByDescending(p => p.FirstName).ThenBy(p => p.Id).Skip(5).Select(p => new { p.FirstName, p.Id, Foo = p.Id * 5 }).ToList();
QueryTestHelpers.VerifyQueryResult(expected, results, (o, i) => o.Id == i.Id);
}
}