-
Notifications
You must be signed in to change notification settings - Fork 30
issue #71 #104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
alexeypj
wants to merge
10
commits into
koenbeuk:master
Choose a base branch
from
alexeypj:feature/issue-71
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
issue #71 #104
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 1 addition & 8 deletions
9
src/EntityFrameworkCore.Projectables/Infrastructure/Internal/CustomQueryCompiler.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 1 addition & 6 deletions
7
...ntityFrameworkCore.Projectables.FunctionalTests/ExtensionsMethods/ExtensionMethodTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
tests/EntityFrameworkCore.Projectables.FunctionalTests/Helpers/SampleBodyParamDbContext.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| using System.Collections.Generic; | ||
| using EntityFrameworkCore.Projectables.Infrastructure; | ||
| using Microsoft.EntityFrameworkCore; | ||
| using Order = EntityFrameworkCore.Projectables.FunctionalTests.MemberBodyParameterValueTests.Order; | ||
| using OrderItem = EntityFrameworkCore.Projectables.FunctionalTests.MemberBodyParameterValueTests.OrderItem; | ||
|
|
||
| namespace EntityFrameworkCore.Projectables.FunctionalTests.Helpers | ||
| { | ||
| public class SampleBodyParamDbContext : DbContext | ||
| { | ||
| readonly CompatibilityMode _compatibilityMode; | ||
|
|
||
| public SampleBodyParamDbContext(CompatibilityMode compatibilityMode = CompatibilityMode.Full) | ||
| { | ||
| _compatibilityMode = compatibilityMode; | ||
|
|
||
| var _orders = new List<Order>() { | ||
| new() { | ||
| Id = 1, | ||
|
|
||
| }, | ||
| new() { | ||
| Id = 2, | ||
|
|
||
| } | ||
| }; | ||
|
|
||
| var _orders_items = new List<OrderItem>() { | ||
| new() { | ||
| Id = 1, | ||
| OrderId = 1, | ||
| Name = "Order_1" | ||
| }, | ||
| new() { | ||
| Id = 2, | ||
| OrderId = 1, | ||
| Name = "Order_2" | ||
| }, | ||
| new() { | ||
| Id = 3, | ||
| OrderId = 2, | ||
| Name = "Order_3" | ||
| }, | ||
| new() { | ||
| Id = 4, | ||
| OrderId = 2, | ||
| Name = "Order_4" | ||
| }, | ||
| }; | ||
|
|
||
| Order!.AddRange(_orders); | ||
| OrderItem!.AddRange(_orders_items); | ||
| SaveChanges(); | ||
| } | ||
|
|
||
| protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) | ||
| { | ||
| optionsBuilder.UseInMemoryDatabase("TestDb"); | ||
| optionsBuilder.UseProjectables(options => { | ||
| options.CompatibilityMode(_compatibilityMode); // Needed by our ComplexModelTests | ||
| }); | ||
| } | ||
|
|
||
| protected override void OnModelCreating(ModelBuilder modelBuilder) | ||
| { | ||
| modelBuilder.Entity<Order>() | ||
| .HasKey(x => x.Id); | ||
| modelBuilder.Entity<OrderItem>().HasKey(x => x.Id); | ||
|
|
||
| } | ||
|
|
||
| public DbSet<Order>? Order { get; set; } | ||
| public DbSet<OrderItem>? OrderItem { get; set; } | ||
| } | ||
| } |
66 changes: 66 additions & 0 deletions
66
tests/EntityFrameworkCore.Projectables.FunctionalTests/MemberBodyParameterValueTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.ComponentModel.DataAnnotations; | ||
| using System.ComponentModel.DataAnnotations.Schema; | ||
| using System.Linq; | ||
| using System.Linq.Expressions; | ||
| using EntityFrameworkCore.Projectables.FunctionalTests.Helpers; | ||
| using Microsoft.EntityFrameworkCore; | ||
| using Xunit; | ||
|
|
||
| namespace EntityFrameworkCore.Projectables.FunctionalTests | ||
| { | ||
| public class MemberBodyParameterValueTests | ||
| { | ||
| public class Order | ||
| { | ||
| [Key, DatabaseGenerated(DatabaseGeneratedOption.None)] | ||
| public int Id { get; set; } | ||
| public List<OrderItem> OrderItem { get; set; } = new List<OrderItem>(); | ||
|
|
||
| [Projectable(UseMemberBody = nameof(GetOrderItemNameExpression), UseMemberBodyArguments = new object[]{ 1 } )] | ||
| public string FirstOrderPropName => GetOrderItemName(1); | ||
|
|
||
|
|
||
| [Projectable(UseMemberBody = nameof(GetOrderItemNameInnerExpression))] | ||
| public string GetOrderItemName(int id) | ||
| => OrderItem.Where(av => av.Id == id) | ||
| .Select(av => av.Name) | ||
| .FirstOrDefault() ?? throw new ArgumentException("Argument matching identifier not found"); | ||
|
|
||
| private static Expression<Func<Order, int, string>> GetOrderItemNameInnerExpression() | ||
| => (@this, id) => @this.OrderItem | ||
| .Where(av => av.Id == id) | ||
| .Select(av => av.Name) | ||
| .FirstOrDefault() ?? string.Empty; | ||
|
|
||
| public static Expression<Func<Order, int, string>> GetOrderItemNameExpression | ||
| => (order, id) => order.GetOrderItemName(id); | ||
| } | ||
|
|
||
| public class OrderItem | ||
| { | ||
| [Key, DatabaseGenerated(DatabaseGeneratedOption.None)] | ||
| public int Id { get; set; } | ||
| public int OrderId { get; set; } | ||
| public string Name { get; set; } = string.Empty; | ||
| } | ||
|
|
||
| [Fact] | ||
| public void UseBodyParameterValue() | ||
| { | ||
| //Arrange | ||
| using var dbContext = new SampleBodyParamDbContext(); | ||
|
|
||
| // Act | ||
| var query = dbContext | ||
| .Set<Order>() | ||
| .Include(a => a.OrderItem) | ||
| .FirstOrDefault(d => d.FirstOrderPropName == "Order_1"); | ||
|
|
||
| // Assert | ||
| Assert.NotNull(query); | ||
| Assert.True(query!.FirstOrderPropName == "Order_1"); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The result will be overwritten by the call on line 24
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think differently that when calling line 20 the expression will not be empty