PrimaryKeyNamingConvention Fluent Automapping

I have a question about using PrimaryKeyNamingConvention Assume 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>(); }); 

Can you use something like the one described above? When you try to execute an error occurs

The 'banco' object does not have an identifier. Use the Id method to match your ID. For example: Id (x => x.Id).

+4
source share
1 answer

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

[Edit] Added code from this question

 public class AutomappingConfiguration : DefaultAutomappingConfiguration { public override bool IsId(Member member) { return member.Name == member.DeclaringType.Name + "Id"; } } 
+2
source

Source: https://habr.com/ru/post/1385023/


All Articles