Skip to content

Commit

Permalink
Add some comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
Reza-Noei committed Jan 4, 2024
1 parent c4fe3d7 commit 0cfbc5c
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,23 @@ private static void MapAllReadonlyProperties<T>(Microsoft.EntityFrameworkCore.Me
var navigations = entityType.GetNavigations().Select(n => n.Name);
IEnumerable<PropertyInfo> properties = from property in typeof(T).GetProperties()
where property.CanWrite == false
&& property.GetCustomAttribute<NotMappedAttribute>() == null
&& property.GetMethod.GetCustomAttribute<CompilerGeneratedAttribute>() != null
&& property.GetCustomAttribute<NotMappedAttribute>() == null
&& property.GetMethod.GetCustomAttribute<CompilerGeneratedAttribute>() != null
&& !ignores.Any(ignoreProperty => ignoreProperty == property.Name)
&& !navigations.Contains(property.Name)
select property;

// about following condition in above code:
// && property.GetMethod.GetCustomAttribute<CompilerGeneratedAttribute>() != null
// getter-only properties and expression-bodied properties are looking so much similar in C#
// 1. public string FullName => $"{FirstName} {LastName}"
// 2. public string FirstName { get; }
// in example #1 there will be no backing-field in compilation process.
// but in the next example (#2) we have a compiler generated backing-field.
// By default EF marks a property as column if it be able to write on it.
// So when we add read-only things to it, we should care about such a case.
// to identify expression-bodied properties we can use this attribute check on GetMethod.

foreach (var property in properties)
{
builder.Instance.Property(property.PropertyType, property.Name);
Expand Down

0 comments on commit 0cfbc5c

Please sign in to comment.