本文介绍了PrimaryKeyNamingConvention Fluent Automapping的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于使用PrimaryKeyNamingConvention
的问题假设以下类:

pre $ public $ banco
{
[必须]
公共虚拟int banco_id {get;组; }
...
}

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












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

你可以使用上面所描述的东西吗?当我尝试运行时发生错误



实体banco没有映射Id。使用Id方法来映射您的身份属性。例如:Id(x => x.Id)。

解决方案

您可以使用这样的ID。但是,您不仅需要映射列名称,还需要映射属性。

代码从

  public class AutomappingConfiguration:DefaultAutomappingConfiguration 
{
public override bool IsId会员)
{
return member.Name == member.DeclaringType.Name +Id;
}
}


I have a question about using PrimaryKeyNamingConventionSuppose 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).

解决方案

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

这篇关于PrimaryKeyNamingConvention Fluent Automapping的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 14:42