Skip to content

ISession.Merge() not returning the entity id for the new entity on version 5.3.x #2632

@Afshin1980

Description

@Afshin1980

I updated the NHibernate from 5.2.7 to 5.3.0 and noticed that there is a difference between the returning object from the merge function. In version 5.3.x the merge function doesn't return the entity id if the entity is not in the database but in version 5.2.7 the merge function returns the entity id. I don't know this is a bug or not

Here is the code

using NHibernate.Cfg;
using NHibernate.Dialect;
using NHibernate.Driver;
using NHibernate.Mapping.ByCode;
using NHibernate.Mapping.ByCode.Conformist;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace TestNHibernate
{
    class Program
    {
        static void Main(string[] args)
        {
            var cfg = new Configuration();

            cfg.DataBaseIntegration(x =>
            {
                x.ConnectionString = "Data Source=.;integrated security=true;Initial Catalog=TestDB;MultipleActiveResultSets=True";
                x.Driver<SqlClientDriver>();
                x.Dialect<MsSql2008Dialect>();
            });

            cfg.AddAssembly(Assembly.GetExecutingAssembly());

            var sefact = cfg.BuildSessionFactory();

            using (var session = sefact.OpenSession())
            {
                var person = new Person
                {
                    Name= "Jamie"
                };

                using (var tx = session.BeginTransaction())
                {
                    var merged = session.Merge(person);

                    session.SaveOrUpdate(merged);
                    tx.Commit();
                }
                                                
                Console.ReadLine();
            }
        }
    }

    public class Person
    {
        public virtual int ID { get; set; }
        public virtual string Name { get; set; }
        public virtual string Tel { get; set; }
    }
}

5 2 7
5 3 0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions