koenbeuk / EntityFrameworkCore.Projectables

Project over properties and functions in your linq queries
MIT License
260 stars 17 forks source link

Nested classes not generated with the outer type name #67

Closed vflame closed 1 year ago

vflame commented 1 year ago

When classes are nested inside another class, the full namespace + outer type isn't generated

koenbeuk commented 1 year ago

Can you clarify or share an example as this should be working. There is a unit test specifically for nested members here:

https://github.com/koenbeuk/EntityFrameworkCore.Projectables/blob/0820252a0238e384624737c5ddb41e3c44f8c0cd/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.cs#L131

vflame commented 1 year ago

Sure, please see below.

The following:

    public class UserDto
    {
        public int Id { get; set; }

        public OrderDto Order { get; set; }

        public class OrderDto
        {
            public int OrderId { get; set; }
        }

    }
    public static class Extensions
    {
        [Projectable]
        public static UserDto ToDto(this User user) => new UserDto() {
            Id = user.Id,
            Order = new UserDto.OrderDto() {
                OrderId = user.Orders.First().OrderId,
            }
        };
    }

Generates:

// <auto-generated/>
#nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{
    [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
    static class BasicSample_Extensions_ToDto
    {
        static global::System.Linq.Expressions.Expression<global::System.Func<global::BasicSample.User, global::BasicSample.UserDto>> Expression()
        {
            return (global::BasicSample.User user) => new global::BasicSample.UserDto()
            {
                Id = user.Id,
                Order = new UserDto.OrderDto()
                {
                    OrderId = global::System.Linq.Enumerable.First(user.Orders).OrderId,
                }
            };
        }
    }
}

image

koenbeuk commented 1 year ago

Should be fixed of #68

Thanks for reporting this!