GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Added out parameter on With methods to fix #184 · ThatRendle/Simple.Data@09e979f

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • Simple.Data.BehaviourTest/Query
    • WithTest.cs
  • Simple.Data
    • SimpleQuery.cs
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Simple.Data.BehaviourTest/Query/WithTest.cs‎

Copy file name to clipboardExpand all lines: Simple.Data.BehaviourTest/Query/WithTest.cs
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,5 +249,28 @@ public void CriteriaReferencesShouldNotBeDuplicatedInSql()
249249

250250
GeneratedSqlIs(expectedSql);
251251
}
252+
253+
/// <summary>
254+
/// Test for issue #184
255+
/// </summary>
256+
[Test]
257+
public void CriteriaReferencesShouldUseWithAlias()
258+
{
259+
const string expectedSql = "select [dbo].[employee].[id],[dbo].[employee].[name]," +
260+
"[dbo].[employee].[managerid],[dbo].[employee].[departmentid]," +
261+
"[foo].[id] as [__with1__foo__id],[foo].[name] as [__with1__foo__name]" +
262+
" from [dbo].[employee] join [dbo].[department] [foo] on ([foo].[id] = [dbo].[employee].[departmentid])" +
263+
" where ([dbo].[employee].[name] like @p1" +
264+
" and [foo].[name] = @p2)";
265+
266+
dynamic foo;
267+
var q = _db.Employees.Query()
268+
.Where(_db.Employees.Name.Like("A%"))
269+
.WithOne(_db.Employees.Department.As("Foo"), out foo)
270+
.Where(foo.Name == "Admin");
271+
EatException(() => q.ToList());
272+
273+
GeneratedSqlIs(expectedSql);
274+
}
252275
}
253276
}
Collapse file

‎Simple.Data/SimpleQuery.cs‎

Copy file name to clipboardExpand all lines: Simple.Data/SimpleQuery.cs
+15-4Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,11 +327,22 @@ public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, o
327327
return false;
328328
}
329329

330-
private static bool MethodIsCallable(MethodInfo mi, InvokeMemberBinder binder, object[] args)
330+
public SimpleQuery With(ObjectReference reference, out dynamic queryObjectReference)
331331
{
332-
return mi.Name.Equals(binder.Name, StringComparison.OrdinalIgnoreCase) &&
333-
mi.GetParameters().Length == 1 &&
334-
Convert.ChangeType(args, mi.GetParameters().Single().ParameterType) != null;
332+
queryObjectReference = reference;
333+
return With(new[] {reference});
334+
}
335+
336+
public SimpleQuery WithOne(ObjectReference reference, out dynamic queryObjectReference)
337+
{
338+
queryObjectReference = reference;
339+
return With(new[] {reference}, WithType.One);
340+
}
341+
342+
public SimpleQuery WithMany(ObjectReference reference, out dynamic queryObjectReference)
343+
{
344+
queryObjectReference = reference;
345+
return With(new[] {reference}, WithType.Many);
335346
}
336347

337348
private SimpleQuery ParseWith(InvokeMemberBinder binder, object[] args)

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.