Automation has no match with identifier

My Entity Class:
public class Building 
    {
        /// <summary>
        /// internal Id 
        /// </summary>
        public virtual long Id { get; set; }
..............
}

My mapping:

var model = AutoMap.AssemblyOf<Building>()
                        .Setup(s => s.FindIdentity = p => p.Name == "Id")
                        .Where(t => t.Namespace == "SpikeAutoMappings");

var database = Fluently.Configure()
                        .Database(DatabaseConfigurer)
                        .Mappings(m=>m.AutoMappings.Add(model));

I need someone to help me understand what is wrong, because I continue this error when running the unit test:

Initialization method TestProject1.MappingTestBase.TestInitialize threw exception. FluentNHibernate.Cfg.FluentConfigurationException:  FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.

 --->  FluentNHibernate.Visitors.ValidationException: The entity doesn't have an Id mapped. Use the Id method to map your identity property. For example: Id(x => x.Id)..
+3
source share
3 answers

both of the above answers are correct; Unless you specify otherwise, the autoperper assumes that you have an Id field. If your identifier is long, the machine may not recognize it correctly.
try defining a MappingOverride for your class (s), for example:

public class UserMappingOverride : IAutoMappingOverride<User>
{
    #region IAutoMappingOverride<User> Members

    public void Override(AutoMapping<User> mapping)
    {
        mapping.Id(u => u.Name);
    }

    #endregion
}

Id() Automapper , ID.
. http://wiki.fluentnhibernate.org/Auto_mapping#Overrides.
Cheers,
Jhonny

+9

, AutoMapping , Id . , NMG .

/ , (Oracle, SQL ).

, /Entities/. :

Preferences

  • = , ( )
  • =
  • =

: # VB

  • : [your project folder]\Entities
  • : [your project namespace].Entities
  • : [your project name].Entities

, , .

*.cs *Map.cs ( Add Existing Item..., ).

Fluent, - :

Id(x => x.keyName_ID)
  .Column(x => x.keyname_ID)
  .GeneratedBy
  .Sequence("keyname_ID")

Id(x => x.keyName_ID)
  .Column(x => x.keyname_ID)
  .GeneratedBy
  .Identity()
  .Column("keyname_ID")

Id(x => x.keyName_ID)
  .Column(x => x.keyname_ID)
  .GeneratedBy
  .Assigned()

, Id, FluentMapping Fluent nHibernate. Id Map . :

Id(x => x.KeyName_ID)
  .GeneratedBy
  .GetGeneratorMapping()
  .IsSpecified("KeyName_ID");

keyname_id - Id , .

, BuildSession :

(...).Mappings(m => 
    m.FluentMappings.AddFromAssemblyOf<[one of your entities]>()
);

Id.:) , !

+1

Automapping , , Entity :

    public virtual int Id { get; private set; }

automapper (.. FindIdenity, AutoMap).

, ID, , long int. , .

0

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


All Articles