本文整理汇总了C#中System.Factory.CreateQuery方法的典型用法代码示例。如果您正苦于以下问题:C# Factory.CreateQuery方法的具体用法?C# Factory.CreateQuery怎么用?C# Factory.CreateQuery使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Factory
的用法示例。
在下文中一共展示了Factory.CreateQuery方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ManyParameters
public void ManyParameters()
{
var factory = new Factory();
var query = (Query)factory.CreateQuery(string.Empty);
var stus = query.All<Student>()
.Where(_ => _.Student_id == 1 && _.Student_id == 1 && _.Student_id == 1 && _.Student_id == 1 && _.Student_id == 1 && _.Student_id == 1 && _.Student_id == 1);
var context = AssertHelper.CreateContext(query, stus);
Assert.AreEqual(7, context.Values.Count);
}
示例2: OrderByReference
public void OrderByReference()
{
var factory = new Factory();
var query = (Query)factory.CreateQuery(string.Empty);
var stus = query.All<Student>()
.OrderBy(_ => _.Course);
var context = AssertHelper.CreateContext(query, stus);
var result = context.Writer.GetResult();
var expected =
@"SELECT [t0].[Student_id], [t0].[Name]
FROM [dbo].[Student] AS [t0] (NOLOCK)
ORDER BY [t0].[Course_id] ASC";
AssertHelper.AreEqualWithNoSpaces(expected, result);
}
示例3: ReferenceNullInWhere
public void ReferenceNullInWhere()
{
var factory = new Factory();
var query = (Query)factory.CreateQuery(string.Empty);
var courses = query.All<Course>()
.Where(_ => _.School != null);
var context = AssertHelper.CreateContext(query, courses);
var result = context.Writer.GetResult();
string expected =
@"SELECT
[t0].[Course_id] , [t0].[Name]
FROM [dbo].[Course] AS [t0] (NOLOCK)
WHERE [t0].[School_id] IS NOT NULL";
AssertHelper.AreEqualWithNoSpaces(expected, result);
}
示例4: EntityRelationAccessInWhere
public void EntityRelationAccessInWhere()
{
var factory = new Factory();
var query = (Query)factory.CreateQuery(string.Empty);
var stus = query.All<Student>()
.Where(_ => _.Course.School.Name.Contains("EF"));
var context = AssertHelper.CreateContext(query, stus);
string expected =
@"SELECT [t0].[Student_id], [t0].[Name]
FROM [dbo].[Student] AS [t0] (NOLOCK)
LEFT JOIN [Course] AS [t1] (NOLOCK)
ON [t0].[Course_id] = [t1].[Course_id]
LEFT JOIN [School] AS [t2] (NOLOCK)
ON [t1].[School_id] = [t2].[School_id]
WHERE [t2].[Name] LIKE @p0";
var result = context.Writer.GetResult();
AssertHelper.AreEqualWithNoSpaces(expected, result);
Assert.AreEqual("%EF%", context.Values["@p0"].Value);
}
示例5: TestOrderBy
public void TestOrderBy()
{
var factory = new Factory();
var query = (Query)factory.CreateQuery(string.Empty);
var stus = query.All<Student>()
.OrderBy(_ => _.Name)
.ThenByDescending(_ => _.Course.Name);
var context = AssertHelper.CreateContext(query, stus);
var result = context.Writer.GetResult();
var expected =
@"SELECT [t0].[Student_id], [t0].[Name]
FROM [dbo].[Student] AS [t0] (NOLOCK)
LEFT JOIN [Course] AS [t1] (NOLOCK)
ON [t0].[Course_id] = [t1].[Course_id]
ORDER BY [t0].[Name] ASC, [t1].[Name] DESC";
AssertHelper.AreEqualWithNoSpaces(expected, result);
}
示例6: TestTake
public void TestTake()
{
var factory = new Factory();
var query = (Query)factory.CreateQuery(string.Empty);
var stus = query.All<Student>()
.Take(10);
var context = AssertHelper.CreateContext(query, stus);
var result = context.Writer.GetResult();
var expected =
@"SELECT TOP(@p0) [t0].[Student_id], [t0].[Name]
FROM [dbo].[Student] AS [t0] (NOLOCK)";
AssertHelper.AreEqualWithNoSpaces(expected, result);
}
示例7: TestSkipWithoutOrder
public void TestSkipWithoutOrder()
{
var factory = new Factory();
var query = (Query)factory.CreateQuery(string.Empty);
var stus = query.All<Student>()
.Skip(10)
.Take(10);
var context = AssertHelper.CreateContext(query, stus);
var result = context.Writer.GetResult();
var expected =
@"SELECT
TOP(@p1)
*
FROM(
SELECT
[t0].[Student_id], [t0].[Name], ROW_NUMBER() OVER ( ORDER BY [t0].[Student_id] ASC) AS [ROW_NUMBER]
FROM [dbo].[Student] AS [t0] (NOLOCK)
) AS [t1]
WHERE [ROW_NUMBER]>@p0";
AssertHelper.AreEqualWithNoSpaces(expected, result);
}