Error "Do not fix error" with NHibernate, NHibernate.Linq and Fluent Mapping

I am using Nhibernate 2.1.2.4000 GA with Nhibernate.Linq 1.0 and the latest version of FluentNhibernate downloaded from the wizard on github.

I do some tests and whenever I try to delete an object obtained using linq query, I get this error:

Do not save: NHibernate.Linq.Query`1 [[Employees.Core.Entities.Employee, Employees.Core, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null]]

All other operations (insert, update and selection) look fine,

My Entity Class:

public class Employee
{
    public Employee()
    {
    }

    public virtual Int32 Id { get; private set; }
    public virtual String Name { get; set; }    

    public virtual String SayHello()
    {
        return String.Format("'Hello World!', said {0}.", Name);
    }
}

Display Class:

public class EmployeeMap : ClassMap<Employee>
{
    public EmployeeMap()
    {
        Id(x => x.Id);
        Map(x => x.Name)
            .Not.Nullable()
            .Length(50);
    }
}

Configuration:

Assembly mappingsAssemly = Assembly.GetExecutingAssembly();

return Fluently.Configure()
    .Database( MsSqlConfiguration.MsSql2008
                    .ConnectionString(connectionString)
                    .ProxyFactoryFactory(typeof(ProxyFactoryFactory))
                    .ShowSql())                            
    .Mappings( m => m.FluentMappings.AddFromAssembly(mappingsAssemly))
    .BuildSessionFactory();

And the code that doesn't work:

public void RemoveAll()
{
    var q = from employee in _session.Linq<Employee>()
            select employee;

    foreach (var employee in q.ToList())
    {
        _session.Delete(q);
    }
}

Any thoughts?

+5
source share
3

!

, .

RemoveAll(), , "q", , IQueriable "employee". .

:

        public void RemoveAll()
        {
            var q = from employee in _session.Linq()
                    select employee;

            var p = q.ToList();

            foreach (var employee in p)
            {
                _session.Delete(employee);
            }
        }
+4

, , FNH (Assembly.GetExecutingAssembly()), , ?

Mappings, ExportTo, FNH ; , . , , , FNH Linq ( ).

Mappings(
  m => m.FluentMappings
          .AddFromAssembly(mappingsAssemly)
          .ExportTo(@"C:\"));

, , - NHibernate Configuration, NH . BuildConfiguration BuildSessionFactory ; ClassMappings ( ), .

, , API- Criteria HQL, , ( linq).

+2

This may be a Linq provider error. You might want to try to reproduce the problem with the latest NHibernate database, which includes a new / different Linq provider. Alternatively, if you have successfully removed Fluent NHibernate from the equation, you can (relatively easily) send a test case / error report against the Linq provider.

+1
source

All Articles