🚀 ویژگیهای جدید EF Core 10 در 10 NET.
🧩 Complex Types (انواع پیچیده)
در EF Core 10 میتوان دادههایی را مدل کرد که به یک Entity تعلق دارند اما هویت مستقل ندارند.
در حالی که Entityها به جدولهای جداگانه در دیتابیس نگاشت میشوند، Complex Typeها میتوانند به ستونهایی در همان جدول (Table Splitting) یا به یک ستون JSON نگاشت شوند.
این قابلیت امکان مدلسازی به سبک Document-Based را فراهم میکند و باعث کاهش JOINها و بهبود عملکرد دیتابیس میشود.
📘 مثال Table Splitting:
modelBuilder.Entity<Customer>(b =>
{
b.ComplexProperty(c => c.ShippingAddress);
b.ComplexProperty(c => c.BillingAddress);
});
✅ Optional Complex Types (انواع پیچیده اختیاری)
EF Core 10
از Complex Typeهای اختیاری نیز پشتیبانی میکند:
public class Customer
{
public int Id { get; set; }
public Address ShippingAddress { get; set; }
public Address? BillingAddress { get; set; }
}
🗃 JSON Mapping (نگاشت به JSON)
اکنون میتوانید Complex Typeها را به ستونهای JSON در دیتابیس نگاشت دهید:
modelBuilder.Entity<Customer>(b =>
{
b.ComplexProperty(c => c.ShippingAddress, c => c.ToJson());
b.ComplexProperty(c => c.BillingAddress, c => c.ToJson());
});
💪 Struct Support (پشتیبانی از Struct)
Complex Type
ها حالا میتوانند از Structها نیز استفاده کنند:
public struct Address
{
public required string Street { get; set; }
public required string City { get; set; }
public required string ZipCode { get; set; }
}
🔗 LeftJoin و RightJoin Operators
در نسخههای قبلی EF Core نوشتن LEFT JOIN بسیار پیچیده بود و نیاز به ترکیب SelectMany, GroupJoin, و DefaultIfEmpty داشت.
در .NET 10 حالا میتوانید با متدهای LeftJoin و RightJoin، کوئریهای تمیزتر و سادهتری بنویسید 👇
var query = context.Students
.LeftJoin(
context.Departments,
student => student.DepartmentID,
department => department.Id,
(student, department) => new { student.Name, Department = department?.Name }
);
🔍 این ویژگیها EF Core را به سمت یک ORM مدرنتر، قدرتمندتر و سازگار با معماریهای Document-oriented و Microservice سوق میدهد.