NHibernate Envers IntegrateWithEnvers error - nhibernate

Receiving no extension method found
'NHibernate.Cfg.Configuration' does not contain a definition for 'IntegrateWithEnvers' and no extension method 'IntegrateWithEnvers' accepting a first argument of type 'NHibernate.Cfg.Configuration' could be found (are you missing a using directive or an assembly reference?)
I am using NHibernate Envers 2, NHibernate 4 and FluentNHibernate 1.4 with asp.net 4.5.
My Configuration is
using CancerConnect.Domain;
using CancerConnect.Infrastructure.Conventions;
using FluentNHibernate.Automapping;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using System;
var enversConf = new NHibernate.Envers.Configuration.Fluent.FluentConfiguration();
enversConf.Audit<Users>();
var cfg = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008.ConnectionString(p => p.FromConnectionStringWithKey("dbConnectionString")))
.Mappings(m => m.AutoMappings.Add(persistenceModel))
.ExposeConfiguration(conf =>
{
conf.IntegrateWithEnvers(enversConf);
})
.BuildConfiguration();
Am I missing anything

The extension method IntegrateWithEnvers is defined in the namespace NHibernate.Cfg see here.
So be sure to add the following using:
using NHibernate.Cfg;
And you will have access to the extension method.

Related

TypeLoadException in ASP.NET DevExtreme Datagrid when specifying columns

I'm customizing the columns I need for a datagrid in DevExtreme. Below is my Index.cshtml and my action method to load the data. The model has more attributes but I only want to include these three.
#(Html.DevExtreme().DataGrid<ServicingRequestOrder.Models.GeneralInfo>
()
.ID("dataGrid")
.ShowBorders(true)
.DataSource(d => d.Mvc().Controller("GeneralInfo").LoadAction("IndexLoad").Key("ID"))
.Columns(columns =>
{
columns.AddFor(m => m.CustomerID);
columns.AddFor(m => m.Name);
columns.AddFor(m => m.Description);
}).
[HttpGet]
public object IndexLoad(DataSourceLoadOptions loadOptions)
{
var generalInfos = _context.GeneralInfos.ToList();
return DataSourceLoader.Load(generalInfos, loadOptions);
}
The specific exception I'm getting is
TypeLoadException: Could not load type 'Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.ExpressionHelper' from assembly 'Microsoft.AspNetCore.Mvc.ViewFeatures, Version=3.1.7.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
I have included this service in my Startup.cs as well.
services.AddMvc().AddJsonOptions(options => options.JsonSerializerOptions.PropertyNamingPolicy = null);
What am I missing here.
TypeLoadException: Could not load type 'Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.ExpressionHelper' from assembly 'Microsoft.AspNetCore.Mvc.ViewFeatures, Version=3.1.7.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
In ASP.NET Core 3.0, some pubinternal APIs (includes Microsoft.AspNetCore.Mvc.ViewFeatures.Internal namespace) are updated to be truly internal, which seems cause this issue.
For more information about "Making "pubinternal" types in MVC internal", please check this link: https://github.com/dotnet/aspnetcore/issues/4932 .
As a possible workaround, you can try to setup the project with ASP.NET Core 2.x rather than ASP.NET Core 3+ version.
The issue is resolved. By default when I installed Devextreme in the dependencies, it wasn't the latest version. After some checking, I had to update the version of Devextreme and it's all good now.

EF Core Missing Method HasIndex

I've just started to migrate to a SQL database and running into a problem with a MissingMethodException being thrown. Here is the configuration class that is throwing the error:
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Project.Core.Entities.Users;
namespace Project.Persistance.Configuration.Users
{
public class UserClaimTypeConfiguration : IEntityTypeConfiguration<UserClaimType>
{
public void Configure(EntityTypeBuilder<UserClaimType> builder)
{
builder.HasKey(entity => entity.Id);
builder.Property(entity => entity.Name)
.IsRequired()
.HasMaxLength(30);
builder.HasIndex(entity => entity.Name);
builder.Property(entity => entity.Description)
.IsRequired(false)
.HasMaxLength(100);
builder.Ignore(entity => entity.ValueType);
}
}
}
And this is error I am getting in the console:
PM> add-migration user
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.MissingMethodException: Method not found: 'Microsoft.EntityFrameworkCore.Metadata.Builders.IndexBuilder Microsoft.EntityFrameworkCore.Metadata.Builders.EntityTypeBuilder`1.HasIndex(System.Linq.Expressions.Expression`1<System.Func`2<!0,System.Object>>)'.
at Project.Persistance.Configuration.Users.UserClaimTypeConfiguration.Configure(EntityTypeBuilder`1 builder)
at Microsoft.EntityFrameworkCore.ModelBuilder.ApplyConfiguration[TEntity](IEntityTypeConfiguration`1 configuration)
I've tried 'Goggle' and the Microsoft docs but can't seem to find any reference to this issue - so it must be my setup. Just can't figure out what is causing it!
Breaking change in .NET Core 3.0 preview 3. Fixed in preview 4:
ASP.NET Core Issue 8467 (RESOLVED)
Based on this document:
https://learn.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.metadata.builders.entitytypebuilder-1.hasindex?view=efcore-3.1
Implementation of this method is done in Microsoft.EntityFrameworkCore versions 3.1 3.0 2.2 2.1 2.0 1.1 1.0
You have to check your Microsoft.EntityFrameworkCore version. It should be one of the above versions. If it does not work for a versoin try another.

Getting started with nhibernate, informix and fluentmapping

I need to configure NHibernate 3.1 to target an informix 11.50 database in an asp.net 4.0 application
using Fluent NHibernate for mappings.
I have this connection string: jdbc:informix-sqli://server:1530/database:informixserver=lufi_tcp
and I have the user an pass. I can connect to to the database using dbvisualizer.
I tray some examples of configuracion that I find on the Internet but it dosen't work.
Can someone get my a link or informacion about what I need to do for
configure nhibernate with fluent to target an informix database (for dummies, please.)
S.O: Windows 8 64 bits
Thanks you in advance.
More information:
I Build the session factory in this way:
class FluentNHibernateLocalSessionFactory : LocalSessionFactoryObject
{
public string[] FluentNhibernateMappingAssemblies { get; set; }
protected override ISessionFactory NewSessionFactory(Configuration config)
{
return Fluently.Configure()
.Database(
IfxSQLIConfiguration
.Informix1000
.Provider<NHibernate.Connection.DriverConnectionProvider>()
.Driver<NHibernate.Driver.IfxDriver>()
.Dialect<NHibernate.Dialect.InformixDialect>()
.ConnectionString("Database=myDatabase;Server=myServer:1530;Persist Security Info=True;Authentication=Server;uid=myUser;password=myPass;")
.ShowSql()
)
.Mappings(m =>
{
foreach (string assemblyName in FluentNhibernateMappingAssemblies)
m.FluentMappings.AddFromAssembly(Assembly.Load(assemblyName));
})
.BuildConfiguration()
.BuildSessionFactory();
}
}
The error I get:
{"Could not create the driver from NHibernate.Driver.IfxDriver, NHibernate, Version=3.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4."}
You have to add a reference to IBM.Data.Informix otherwise the driver will throw this exception. To do so you have to add a reference to IBM.Data.Informix.dll to the project which is running your code above.

How to configure the database tables with Fluent?

Iam trying to generate the tables of the database but the tables are not generated.
I'm doing the mapping like this:
using Domain.Entidades;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using NHibernate.Tool.hbm2ddl;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Domain.Infraestrutura
{
public class Conexao
{
public static void CriarTabelasBanco()
{
FluentConfiguration configuration = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008.ConnectionString(x => x.FromConnectionStringWithKey("psConnection")).ShowSql())
.ExposeConfiguration(cfg => new SchemaExport(cfg).Create(true, true))
.Mappings(x => x.FluentMappings.AddFromAssemblyOf<Pessoa>());
configuration.BuildSessionFactory();
}
}
}
Add your mappings first and then call ExposeConfiguration, otherwise the mappings are not known to the config at the point you call the SchemaExport.
Apart from that, SchemaExport fails silently, so if there are any errors, it will not throw and exception, instead you can have a look into the exceptions list of the SchemaExport instance, therefore you would have to structure the call slightly different.

Warning when upgrading Fluent 1.2 from NH 3.0 to 3.1 -- ProxyFactoryFactory is obsolete, moved to

I'm fairly new to NHibernate and Fluent NHibernate and I've been using Fluent 1.2 for NH 3.0 for about 6 months. I just upgraded to Fluent 1.2 for NH 3.1. Now I'm getting a warning (in Visual Studio), and I've tried to fix it but no luck. I could use some help...
In my Global.asax file, I Fluently-configure NHibernate:
var nhConfig = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008.ConnectionString(connstr => connstr.FromConnectionStringWithKey("MyDatabase"))
.ProxyFactoryFactory<ProxyFactoryFactory>().AdoNetBatchSize(100))
.Mappings(mappings => mappings.FluentMappings.AddFromAssemblyOf<MyClass>())
.ExposeConfiguration(c => c.Properties.Add("current_session_context_class", "web"))
.BuildConfiguration();
I'm getting a warning on the line:
.ProxyFactoryFactory<ProxyFactoryFactory>().AdoNetBatchSize(100))
Here's the warning:
FluentNHibernate.Cfg.Db.PersistenceConfiguration<FluentNHibernate.Cfg.Db.MsSqlConfiguration,
FluentNHibernate.Cfg.Db.MsSqlConnectionStringBuilder>.ProxyFactoryFactory<TProxyFactoryFactor y>()'
is obsolete: 'Moved to FluentConfiguration Fluently.Configure().ProxyFactoryFactory(...))'
I think I need to use the FluentlyConfigure().ProxyFactoryFactory(), but the help/intellisense for that method says it's only for NH 2.1.
What should I be doing in my configuration to eliminate this warning and not use obsolete/deprecated methods?
Thanks.
In the last couple of FluentNHibernate builds, the ProxyFactoryFactory method was moved out of Database to directly off of Configure. Try this:
var nhConfig = Fluently.Configure()
.ProxyFactoryFactory<ProxyFactoryFactory>()
.Database(MsSqlConfiguration.MsSql2008.ConnectionString(c => c.FromConnectionStringWithKey("MyDatabase").AdoNetBatchSize(100))
.Mappings(mappings => mappings.FluentMappings.AddFromAssemblyOf<MyClass>())
.ExposeConfiguration(c => c.Properties.Add("current_session_context_class", "web"))
.BuildConfiguration();