We're getting started with plugging in (Fluent) NHibernate 2.1.2 onto a legacy ASP.NET application.
Previously we've been connecting to an Oracle 9 database using System.Data.OracleClient, but because of some requirements (namely with using Oracle SPs with HBM maps), it seems that at least for the NH component, we'll have to adapt the Oracle.DataAccess.dll instead.
For the most part, we've managed to get that bit working by doing the following:
Adding and referencing the 9.2.0.700 Oracle.DataAccess.dll into the data layer.
Qualifying the Oracle.DataAccess assembly via the web.config. [via]
Adding OraOps9.dll into the application, and setting it to Embedded Resource.
The last step, we've done because our version of the ODP references it, but we have limited capacity to make sure that it will be present on the production server eventually.
This eventually led to getting an InvalidCastException:
Unable to cast object of type
'Oracle.DataAccess.Client.OracleConnection'
to type
'System.Data.Common.DbConnection'
Sifting around for a solution, the status quo seemed to be to ensure that the hbm2dll.keywords property in the NH configuration was set to none. I've done that in both a dynamically created config, and the fluent call to create a SessionFactory.
NHibernate.Cfg.Configuration cfg =
new NHibernate.Cfg.Configuration()
.SetProperty("dialect", "NHibernate.Dialect.Oracle9iDialect")
.SetProperty("connection.driver_class", "NHibernate.Driver.OracleDataClientDriver")
.SetProperty("connection.connection_string",conn)
.SetProperty("connection.provider","NHibernate.Connection.DriverConnectionProvider")
.SetProperty("hbm2dll.keywords","none")
;
_sessionFactory = Fluently.Configure(cfg)
.Database ( OracleDataClientConfiguration.Oracle9.ConnectionString(conn) )
.Mappings ( x => x.FluentMappings.AddFromAssemblyOf<MyDL>() )
.Mappings ( x => x.HbmMappings.AddFromAssemblyOf<MyEntity>() )
.ExposeConfiguration(x => x.Properties.Add("hbm2dll.keywords", "none"))
.BuildSessionFactory()
;
But even so, I still get the same InvalidCastException.
Is there anything else that could be causing this? Are any of my calls above accidentally tripping the hbm2dll.keywords property value back to something else? Any ideas?
ODP 9 is WAY too old and IIRC it's compiled against .NET 1.1.
You need to use ODP 10 at least.
Related
I'm trying to migrate from Startup model to the minimal .NET 6 WebApplication method of running a web application, and I'm specifically interested in keeping the CaptureStartupErrors functionality working.
I am calling the following line on my WebApplicationBuilder, but it makes no difference:
webApplicationBuilder.WebHost.CaptureStartupErrors(true);
Since the code is now simply all laid out flat in the Program.cs' Main method, I actually don't know how this would actually work. If I throw an exception there, it will just exist the program. Am I missing something?
I've just installed the following latest packages from NuGet:
FluentNHibernate.1.3.0.733
NHibernate.3.3.2.4000 (was required for FNH)
I'm trying to get our ASP.NET MVC 3 app running using SQL 2012 (native).
The following code is taken from our method which builds our nhibernate Session:
var sqlConfig = MsSqlConfiguration.MsSql2005.ConnectionString(ConnectionString).AdoNetBatchSize(30);
We also use this approach for provisioning a new emtpy DB using the code first approach.
I need to use the SQL 2012 dialiect but neither the latest FNH or NHibernate have it from NuGet.
Does anyone kow the status of the code in Git for these? I can see a merge for FNH for this 2012 dialiect was done 7 months ago (a month after the latest NuGet was released).
What are others doing to connect to SQL 2012?
Does anyone know when the next NuGet packagaes for these will be available?
Just use the SQL Server 2008 dialect. I don't know of any changes in 2012 that would require an update to the dialect.
It's already supported by the NHibernate core, so it's just a matter of using MsSql2012Dialect:
var sqlConfig = MsSqlConfiguration.MsSql2005.Dialect<MsSql2012Dialect>();
MsSqlConfiguration.MsSql2012 was added to Fluent shortly after the latest release, so you can grab the source if you want, but the end result is the same.
My current setup is using NHibernate (3.3.2.4000) and FluentNHibernate (1.3.0.733) and the first part of my connection setup looks like this, feel free to adapt it to your needs. Note that even though I pull the connection string using the MsSql2008 configuration class, I have set my dialect to MsSql2012Dialect
var cfg = Fluent.NHibernate.Cfg.Fluently.Configure()
.Database(FluentNHibernate.Cfg.Db.MsSqlConfiguration.MsSql2008
.ConnectionString(c => c.FromConnectionStringWithKey("KeyName"))
#if DEBUG
.ShowSql()
.FormatSql()
#endif
.Dialect<NHibernate.Dialect.MsSql2012Dialect>()
.AdoNetBatchSize(50)
)
//Other chained methods (for setting up cache, mappings, etc)
//.Mappings(m =>
//{
//
//}
var sessionFactory = cfg.BuildSessionFactory();
from what I can see the 2012 Dialect just adds support for Sequences and registers iif as a function.
my working environment is C#, Visual Studio 12, entity framework 5 DBContext, SQL Server 2008R2.
the generated entities sets are generated as Hash sets.
xtraGrid.DataSource = _order.OrderLines;
when I type data in the new row, data disappears when focus lost.
With using older entity framework, this logic was working.
What type should I choose for my entity set in order to solve my problem.
Thanks.
I changed type from HashSet to BindingList, and it works, God thank you.
I setup an object context like this:
public MyObjectContext(....) : this(contextName, new EntityConnection(connectionString))
The connection string is a connection string to an Oracle database. I use DevArt as a provider btw.
Everything works fine. I can use it to retrieve entities etc.
But then I wanted to do something with the underlying connection. I did something like:
(OracleConnection)((EntityConnection)context.Connection.StoreConnection)
Which gives me the following exception:
SystemInvalidCastException: [A]Devart.Data.Oracle.OracleConnection cannot be converted to [B]Devart.Data.Oracle.OracleConnection. .... Type A is from C:\Windows\....\6.60.283\.... Type B is from C:\DevDirectory\...\7.2.104.0
It seems that the ObjectContext uses an old version of the DLL. However if I check the references of my project I see a reference to the correct version 7.2.104.0. As I checked further the ObjectContext can still connect even if I have no reference at all in the Subproject where its class is.
How does it resolve the DLL it uses to connect?
Yeah I just realized that I still had the wrong version (6) of devArt installed (globally) but referenced the right version (7) in the project. The assembly containing the ObjectContext had no reference so it needed to get the version from the GAC which was the old one (6).
Thx. For the clarification.
we have an MVC 3.0 project with a quite big domain. The domain access the database via Fluent NHibernate 3.0.
The project is in production since several month, with no problem at all.
Today we are developing a Windows Service accessing the same domain in order to perform some batch operation.
NHibernate could not initialize given the following error
NHibernate.InstantiationException could not load test type: <Foo>
Inner Exception: Object reference not set to an instance of an object.
The internet site it still working flowlessy.
According to infos found in internet this problem rises when there are some Property whiting POCO having initialization in the ctor. In effect there are many of these in the domain, but the question is, why MVC poject doesn't explode and win32 does with the same domain?
Stefano
The NHibernate error message was totally misleading because
it was a value not present in the applicationConfig section of app.configm that had nothing to do with NHibernate or the mapping.
This is for future reference if anyone will find a similar problem.