-
Notifications
You must be signed in to change notification settings - Fork 929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Wrong" SQL Statement generated within Visual Studio 2022 targeting .NET 7 when entity is derived from a base class and not all properties are mapped #3207
Comments
I don't have time to investigate but my bet it's some MappingByCode quirk (maybe due to some .net 7 bug). Check how xml mappings look like in .net 7 and .net 6 using something like this: //Somewhere in your application you have code similar to
var mapper = new ModelMapper();
HbmMapping mapping = mapper.CompileMapping...();
//Add this
var mappingXml = mapping.AsString();
File.WriteAllText("mappings.xml", mappingXml); |
Wow. Can confirm that. This is a blocker issue for us to migrate to net7. But I were not yet able to do a proper repro. But there is definitely some issue with Conform mapping. @bahusoid here a mapping diff: net6 <?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" namespace="Common.Entities" assembly="Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" xmlns="urn:nhibernate-mapping-2.2">
<class name="DerivedClass2" lazy="false" table="DERIVED_CLASS_2">
<id name="Id" type="Int32">
<generator class="assigned" />
</id>
<property name="ClassProp1" />
<property name="ClassProp2" column="CLASS_PROP_2" />
</class>
<class name="DerivedClass" lazy="false" table="DERIVED_CLASS">
<id name="Id" type="Int32">
<generator class="assigned" />
</id>
<property name="ClassProp1" />
<property name="ClassProp2" column="CLASS_PROP_2" />
<property name="BaseProp1" column="BASE_PROP_1" />
<property name="BaseProp2" column="BASE_PROP_2" />
<property name="BaseProp3" column="BASE_PROP_3" />
</class>
</hibernate-mapping> net7 <?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" namespace="Common.Entities" assembly="Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" xmlns="urn:nhibernate-mapping-2.2">
<class name="DerivedClass2" lazy="false" table="DERIVED_CLASS_2">
<id name="Id" type="Int32">
<generator class="assigned" />
</id>
<property name="ClassProp1" />
<property name="ClassProp2" column="CLASS_PROP_2" />
<property name="BaseProp1" column="BASE_PROP_1" />
<property name="BaseProp2" column="BASE_PROP_2" />
<property name="BaseProp3" column="BASE_PROP_3" />
</class>
<class name="DerivedClass" lazy="false" table="DERIVED_CLASS">
<id name="Id" type="Int32">
<generator class="assigned" />
</id>
<property name="ClassProp1" />
<property name="ClassProp2" column="CLASS_PROP_2" />
<property name="BaseProp1" column="BASE_PROP_1" />
<property name="BaseProp2" column="BASE_PROP_2" />
<property name="BaseProp3" column="BASE_PROP_3" />
</class>
</hibernate-mapping> |
Seems that this issue is related to dotnet/runtime#78218 In NH code method nhibernate-core/src/NHibernate/Mapping/ByCode/ExplicitlyDeclaredModel.cs Lines 104 to 107 in b949b7b
|
Sorry for spam. @vie-mo this issue in NH-core can be closed. There is nothing NH team can do at this point of time. So we just need to wait for a net7 hotfix release. |
Thanks for your findings, closing as external. |
FYI, net |
I have a strange failure if i use NHibernate in my application in .NET 7 (port from .NET 6). I have made a littel Visual Studio 2022 solution to reproduce that behaviour and attached it.
In the VS solution there are 3 projects:
In the project Common exists a SQLite database testdb.sqlite with two tables (but no rows):
Table Derived_Class:
Table Derived_Class_2:
NB: the naming with and without underscores was just for testing the mappings!
These tables are mapped to classes as follows:
Both classes are derived from ObjectBase ...
...but as you can see in the mapping, no property from the abstract base class is mapped for DerivedClass2.
If i run the ConsoleNet7 project within Visual Studio 2022 (with or without debugging) the line
executes correct and the line
which resides in the DummyService class in the project Common, produces the following error message:
And that is correct...there is no column named BASE_PROP_1 on table DERIVED_CLASS_2 only on DERIVED_CLASS !!
So why is this statement generated this way and why with the correct (!!) column name from table DERIVED_CLASS ??
If i run the same statements within the .NET 6 console project, then the result or behaviour is correct and no error is displayed for the second select:
I also get these behaviour if i use Oracle or SQL Server but for testing and submitting the SQLite Version is better.
And now the absolut strange thing....
If i execute either the .NET6 or .NET7 console app directly in a command prompt on my machine, then both of them, also the .NET7 one, are working correct !!! The described error is only within Visual Studio 2022 targeting .NET 7 present.
I also checked with a complete clean install of Windows 11 (all patches) and a clean install of Visual Studio 2022 and got the same result.
Maybe i am missing something, but i don't know what.
Solution1.zip
The text was updated successfully, but these errors were encountered: