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
Simple.Data.BehaviourTest/Query
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: Simple.Data.BehaviourTest/Query/WithTest.cs +23Lines changed: 23 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -249,5 +249,28 @@ public void CriteriaReferencesShouldNotBeDuplicatedInSql() |
249 | 249 |
|
250 | 250 | GeneratedSqlIs(expectedSql); |
251 | 251 | } |
| 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 | + } |
252 | 275 | } |
253 | 276 | } |
Collapse file
Copy file name to clipboardExpand all lines: Simple.Data/SimpleQuery.cs +15-4Lines changed: 15 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -327,11 +327,22 @@ public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, o |
327 | 327 | return false; |
328 | 328 | } |
329 | 329 |
|
330 | | - private static bool MethodIsCallable(MethodInfo mi, InvokeMemberBinder binder, object[] args) |
| 330 | + public SimpleQuery With(ObjectReference reference, out dynamic queryObjectReference) |
331 | 331 | { |
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); |
335 | 346 | } |
336 | 347 |
|
337 | 348 | private SimpleQuery ParseWith(InvokeMemberBinder binder, object[] args) |
|