PrimaryKeyNamingConvention Fluent Automapping

独自空忆成欢 提交于 2019-12-12 11:53:17

问题


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:


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";
    }
}


来源:https://stackoverflow.com/questions/8408639/primarykeynamingconvention-fluent-automapping

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!