PrimaryKeyNamingConvention Fluent Automapping

2019-06-24 11:48发布

I have a question about using PrimaryKeyNamingConvention Suppose the following class:

public class banco
{
    [Required]
    public virtual int banco_id { get; set; }
   ...
}

and

public class PrimaryKeyNamingConvention : IIdConvention
{
    public void Apply(IIdentityInstance instance)
    {
        instance.Column(instance.EntityType.Name + "_id");
    }
}

and

 static AutoPersistenceModel CreateAutomappings()
 {
 ... Conventions.Setup(c =>
            {
                c.Add<PrimaryKeyNamingConvention>();
             });

You can use something like described above? When I try to run an error occurs

The entity 'banco' doesn't have an Id mapped. Use the Id method to map your identity property. For example: Id(x => x.Id).

1条回答
Luminary・发光体
2楼-- · 2019-06-24 12:12

You can use such Ids. But you need to map not only column name, but property name also.

[Edit] Code added from this question

public class AutomappingConfiguration : DefaultAutomappingConfiguration
{
    public override bool IsId(Member member)
    {
        return member.Name == member.DeclaringType.Name + "Id";
    }
}
查看更多
登录 后发表回答