From 6b5e46107baba5c11c91bf8250ff38570c797218 Mon Sep 17 00:00:00 2001
From: DocSvartz <svartzdoctor@gmail.com>
Date: Fri, 20 Mar 2026 15:36:29 +0500
Subject: [PATCH 1/2] fix(ProjectToType): add Test case

---
 src/Mapster.EFCore.Tests/EFCoreTest.cs     | 31 ++++++++++++++++++++++
 src/Mapster.EFCore.Tests/Models/Student.cs |  1 +
 2 files changed, 32 insertions(+)

diff --git a/src/Mapster.EFCore.Tests/EFCoreTest.cs b/src/Mapster.EFCore.Tests/EFCoreTest.cs
index 6fba5c15..1a61eabc 100644
--- a/src/Mapster.EFCore.Tests/EFCoreTest.cs
+++ b/src/Mapster.EFCore.Tests/EFCoreTest.cs
@@ -117,6 +117,37 @@ public void MergeIncludeWhenUsingEFCoreProjectToType()
             first.Enrollments.Count.ShouldBe(1);
             first.LastName.ShouldBe("Alexander");
         }
+
+        /// <summary>
+        /// https://github.com/MapsterMapper/Mapster/issues/875
+        /// </summary>
+        [TestMethod]
+        public void NotMemberNameEFCoreProjectToType_not_Error()
+        {
+            var options = new DbContextOptionsBuilder<SchoolContext>()
+                .UseInMemoryDatabase(Guid.NewGuid().ToString("N"))
+                .Options;
+            var context = new SchoolContext(options);
+            DbInitializer.Initialize(context);
+
+            var config = new TypeAdapterConfig();
+
+                config
+                    .NewConfig<Student, StudentDto>()
+                    .Map(dest => dest.LastName, src => src.GetLastName());
+   
+            Should.NotThrow(() =>
+            {
+                var query = context.Students
+               .Include(x => x.Enrollments.OrderByDescending(x => x.StudentID).Take(1))
+               .EFCoreProjectToType<StudentDto>(config);
+            });
+
+        }
+
+
+
+
     }
 
     public class StudentDto
diff --git a/src/Mapster.EFCore.Tests/Models/Student.cs b/src/Mapster.EFCore.Tests/Models/Student.cs
index 36127fde..69a863e8 100644
--- a/src/Mapster.EFCore.Tests/Models/Student.cs
+++ b/src/Mapster.EFCore.Tests/Models/Student.cs
@@ -11,5 +11,6 @@ public class Student
         public DateTime EnrollmentDate { get; set; }
 
         public ICollection<Enrollment> Enrollments { get; set; }
+        public string GetLastName () { return LastName; }
     }
 }

From 5c63ddcb41e045d60076093ad9b3d06e2bbae76c Mon Sep 17 00:00:00 2001
From: DocSvartz <svartzdoctor@gmail.com>
Date: Fri, 20 Mar 2026 15:37:25 +0500
Subject: [PATCH 2/2] fix(ProjectToType): fix 10.0 regression - member name is
 null

---
 src/Mapster.Core/Utils/ProjectToTypeVisitors.cs | 6 +++---
 src/Mapster.EFCore/EFCoreExtensions.cs          | 2 +-
 src/Mapster/Adapters/BaseClassAdapter.cs        | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/Mapster.Core/Utils/ProjectToTypeVisitors.cs b/src/Mapster.Core/Utils/ProjectToTypeVisitors.cs
index 5ee11e7a..324effe0 100644
--- a/src/Mapster.Core/Utils/ProjectToTypeVisitors.cs
+++ b/src/Mapster.Core/Utils/ProjectToTypeVisitors.cs
@@ -5,7 +5,7 @@ namespace Mapster.Utils
 {
     public sealed class TopLevelMemberNameVisitor : ExpressionVisitor
     {
-        public string? MemeberName { get; private set; }
+        public string? MemberName { get; private set; }
 
         public override Expression Visit(Expression node)
         {
@@ -15,8 +15,8 @@ public override Expression Visit(Expression node)
             {
                 case ExpressionType.MemberAccess:
                     {
-                        if (string.IsNullOrEmpty(MemeberName))
-                            MemeberName = ((MemberExpression)node).Member.Name;
+                        if (string.IsNullOrEmpty(MemberName))
+                            MemberName = ((MemberExpression)node).Member.Name;
 
                         return base.Visit(node);
                     }
diff --git a/src/Mapster.EFCore/EFCoreExtensions.cs b/src/Mapster.EFCore/EFCoreExtensions.cs
index 4ed597f0..d93e2f6c 100644
--- a/src/Mapster.EFCore/EFCoreExtensions.cs
+++ b/src/Mapster.EFCore/EFCoreExtensions.cs
@@ -82,7 +82,7 @@ public override Expression Visit(Expression node)
                                 var memberv = new TopLevelMemberNameVisitor();
                                 memberv.Visit(item);
 
-                                IncludeExpression.TryAdd(memberv.MemeberName, item);
+                                IncludeExpression.TryAdd(memberv.MemberName, item);
                             }
                         }
                         return base.Visit(node);
diff --git a/src/Mapster/Adapters/BaseClassAdapter.cs b/src/Mapster/Adapters/BaseClassAdapter.cs
index 4e246dc6..41208035 100644
--- a/src/Mapster/Adapters/BaseClassAdapter.cs
+++ b/src/Mapster/Adapters/BaseClassAdapter.cs
@@ -50,7 +50,7 @@ select fn(src, destinationMember, arg))
 
                     s.Visit(getter);
 
-                    if (arg.Settings.ProjectToTypeResolvers.TryGetValue(s.MemeberName, out var match))
+                    if (s.MemberName != null && arg.Settings.ProjectToTypeResolvers.TryGetValue(s.MemberName, out var match))
                     {
                         arg.Settings.Resolvers.Add(new InvokerModel
                         {
