NHibernate многие к одному результаты в операции не поддерживается - PullRequest
0 голосов
/ 11 июня 2018

Привет, я делаю веб-приложение на .net core 2, используя NHibernate.Когда я пытаюсь добавить несколько к одному сопоставлению в .xml, я получаю следующее исключение:

fail: Microsoft.AspNetCore.Server.Kestrel[13]
      Connection id "0HLEFGR5COP4F", Request id "0HLEFGR5COP4F:00000002": An unhandled exception was thrown by the application.
System.PlatformNotSupportedException: Operation is not supported on this platform.
   at System.Reflection.RuntimeMethodInfo.GetObjectData(SerializationInfo info, StreamingContext context)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeISerializable(JsonWriter writer, ISerializable value, JsonISerializableContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeISerializable(JsonWriter writer, ISerializable value, JsonISerializableContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeISerializable(JsonWriter writer, ISerializable value, JsonISerializableContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList(JsonWriter writer, IEnumerable values, JsonArrayContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
   at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)
   at Microsoft.AspNetCore.Mvc.Formatters.JsonOutputFormatter.WriteObject(TextWriter writer, Object value)
   at Microsoft.AspNetCore.Mvc.Formatters.JsonOutputFormatter.<WriteResponseBodyAsync>d__11.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeResultAsync>d__19.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeNextResultFilterAsync>d__24.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResultExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeNextResourceFilter>d__22.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeFilterPipelineAsync>d__17.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeAsync>d__15.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Hosting.Internal.RequestServicesContainerMiddleware.<Invoke>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Frame`1.<ProcessRequestsAsync>d__2.MoveNext()

Я запускаю его на Linux.Также пробовал на windows 10, но результат тот же.

Без двух сопоставлений многие-к-одному все работает нормально.Вот XML:

<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true" assembly="FuelConsumption" namespace="FuelConsumption">
<class name="Car" table="CARS" dynamic-update="true">
    <id name="Id" column="CAR_ID" type="int">
        <generator class="native"></generator>
    </id>
    <property name="NumberPlate" column="NUMBER_PLATE" type="String"/>
    <property name="Model" column="MODEL" type="string"/>
    <property name="KmCounter" column="KM_COUNTER" type="int"/>
</class>
<class name="Driver" table="DRIVERS" dynamic-update="true">
    <id name="Id" column="DRIVER_ID" type="int">
        <generator class="native"></generator>
    </id>
    <property name="FirstName" column="FIRST_NAME" type="string"/>
    <property name="LastName" column="LAST_NAME" type="string"/>
    <property name="UserName" column="USER_NAME" type="string"/>
    <property name="PassHash" column="PASS_HASH" type="string"/>
    <property name="PassSalt" column="PASS_SALT" type="string"/>
    <property name="HashAlg" column="HASH_ALG" type="string"/>
    <property name="IsAdmin" column="IS_ADMIN" type="bool"/>
</class>
<class name="Refueling" table="REFUELINGS" dynamic-update="true">
    <id name="Id" column="REFUELING_ID" type="int">
        <generator class="native"></generator>
    </id>
    <property name="Date" column="DATE" type="DateTime"/>
    <property name="FuelLiters" column="FUEL_LITERS" type="float"/>
    <property name="TripKm" column="TRIP_KM" type="int"/>

    <many-to-one name="Car" column="FK_CAR_ID" fetch="join" not-null="true" cascade="all"/>
    <many-to-one name="Driver" column="FK_DRIVER_ID" fetch="join" not-null="true" cascade="all"/>
</class>

Refueling.cs:

private Car car;
public virtual Car Car
{
    get => car;
    set => car = value;
}
private Driver driver;
public virtual Driver Driver
{
    get => driver;
    set => driver = value;
}

База данных: enter image description here

...