Код: Выделить всё
public class User : TableFieldsBase, IEntityTypeConfiguration
{
public void Configure(EntityTypeBuilder builder)
{
var tableName = this.GetType().Name;
builder.ToTable(tableName);
var props = GetType().GetProperties();
foreach(var prop in props)
{
var descriptionAttr = this.GetAttributeFrom(prop.Name);
if(descriptionAttr != null)
{
builder.Property(t => EF.Property(t, prop.Name)).HasComment(descriptionAttr.Description);
}
}
}
[Description("This is the username")]
public string Username { get; set; }
[DisplayName("Email")]
public string Email { get; set; }
}
< /code>
Как видите, я зацикливаю все свойства модели и извлекая текст описания. Например, имя пользователя Код: Выделить всё
Exception has occurred: CLR/System.ArgumentException
Exception thrown: 'System.ArgumentException' in Microsoft.EntityFrameworkCore.dll: 'The expression 't => Property(t, value(Backend.Classes.Api.Avpf.Core.Models.User+c__DisplayClass0_0).prop.Name)' is not a valid property expression. The expression should represent a simple property access: 't => t.MyProperty'.'
at Microsoft.EntityFrameworkCore.Infrastructure.ExpressionExtensions.GetPropertyAccess(LambdaExpression propertyAccessExpression)
at Microsoft.EntityFrameworkCore.Metadata.Builders.EntityTypeBuilder`1.Property[TProperty](Expression`1 propertyExpression)
at Backend.Classes.Api.Avpf.Core.Models.User.Configure(EntityTypeBuilder`1 builder) in Models\User.cs:line 38
Подробнее здесь: https://stackoverflow.com/questions/655 ... del-in-ent
Мобильная версия