나는 아직도 NHibernate에 대해 꽤 새롭다는 것을 인정해야한다.NHibernate 설정, 외래 키
나는 2 개의 POCO, Log
및 UserProfile
을 가지고있다. 본질적으로 명확하지 않은 경우 로그 항목은 사용자 프로필을 참조 할 수 있으며 사용자 프로필은 관련된 많은 로그 항목을 가질 수 있습니다. 매핑 파일은 다음과 같이 :
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="C3.DataModel.Generated"
namespace="C3.DataModel">
<class name="Log" table="Logs">
<id name="LogId">
<generator class="guid" />
</id>
<property name="TimeStamp" column="TimeStamp" index="ixLogTimeStamp" not-null="false" />
<property name="Thread" length="255" column="Thread" not-null="false" />
<property name="Severity" column="Severity" />
<property name="Source" length="255" not-null="false" column="Source" />
<property name="Message" length="4000" not-null="false" column="Message" />
<property name="Exception" length="4000" column="Exception" not-null="true" />
<many-to-one name="UserProfile" not-null="false" class="UserProfile" foreign-key="UserID" column="UserID" />
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="C3.DataModel.Generated"
namespace="C3.DataModel">
<class name="UserProfile" table="UserProfiles">
<id name="UserID">
<generator class="assigned" />
</id>
<property name="GivenName" length="40" column="GivenName" />
<property name="MiddleName" length="40" column="MiddleName" not-null="false" />
<property name="FamilyName" length="40" column="FamilyName" />
<property name="UserName" length="250" index="ixUserName" unique="true" />
<property name="NickName" length="40" column="NickName" />
<property name="Address1" length="50" column="Address1" />
<property name="Address2" length="50" column="Address2" />
<property name="City" length="50" column="City" />
<property name="State" length="2" column="State" />
<property name="ZipCode" length="10" column="ZipCode" />
<property name="Bio" length="2000" column="Bio" not-null="false" />
<property name="BirthDate" not-null="false" column="BirthDate" />
<property name="LinkToAvatar" length="250" column="LinkToAvatar" not-null="false" />
<property name="LinkToWebpage" length="250" column="LinkToWebPage" not-null="false" />
<bag name="ActivityLogs" cascade="none" table="Logs" >
<key column="LogId" />
<one-to-many class="Log"/>
</bag>
</class>
</hibernate-mapping>
나는 PostgreSQL 데이터베이스에 대해 내 스키마를 구축하기 위해 노력하고있어 때, 나는 다음과 같은 오류가 나타납니다
NHibernate.HibernateException: ERROR: 42804: foreign key constraint "fkf9c1212b275a3569" cannot be implemented ---> Npgsql.NpgsqlException: ERROR: 42804: foreign key constraint "fkf9c1212b275a3569" cannot be implemented
at Npgsql.NpgsqlState.<ProcessBackendResponses_Ver_3>d__a.MoveNext()
at Npgsql.ForwardsOnlyDataReader.GetNextResponseObject()
at Npgsql.ForwardsOnlyDataReader.GetNextRowDescription()
at Npgsql.ForwardsOnlyDataReader.NextResult()
at Npgsql.ForwardsOnlyDataReader..ctor(IEnumerable`1 dataEnumeration, CommandBehavior behavior, NpgsqlCommand command, NotificationThreadBlock threadBlock, Boolean synchOnReadError)
at Npgsql.NpgsqlCommand.GetReader(CommandBehavior cb)
at Npgsql.NpgsqlCommand.ExecuteNonQuery()
at NHibernate.Tool.hbm2ddl.SchemaExport.ExecuteSql(IDbCommand cmd, String sql)
at NHibernate.Tool.hbm2ddl.SchemaExport.Execute(Action`1 scriptAction, Boolean export, Boolean throwOnError, TextWriter exportOutput, IDbCommand statement, String sql)
at NHibernate.Tool.hbm2ddl.SchemaExport.Execute(Action`1 scriptAction, Boolean export, Boolean justDrop, IDbConnection connection, TextWriter exportOutput)
at NHibernate.Tool.hbm2ddl.SchemaExport.Execute(Action`1 scriptAction, Boolean export, Boolean justDrop)
--- End of inner exception stack trace ---
at NHibernate.Tool.hbm2ddl.SchemaExport.Execute(Action`1 scriptAction, Boolean export, Boolean justDrop)
at NHibernate.Tool.hbm2ddl.SchemaExport.Execute(Boolean script, Boolean export, Boolean justDrop)
at NHibernate.Tool.hbm2ddl.SchemaExport.Create(Boolean script, Boolean export)
at C3.DataModel.Repositories.NHibernateHelper.CreateSchema() in C:\projects\C3\C3.DataModel.Generated\Repositories\NHibernateHelper.cs:line 41
는 SQL는 시간에 실행하려고를 내가 뭘 기대하고 있었는지 명확하지 않은 ...
alter table Logs add constraint FKF9C1212B275A3569 foreign key (LogId) references UserProfiles
,하지만 난 어디를 해결하는 방법을 알고하지 않습니다 : 죽음이다. 내가 잘못한 것을 먼저 말해주고, 빠른 재판을 받으십시오. 당신이 그것을 설명 할 수있어서 내가 잘못 된 곳을 이해할 수 있다면, 나는 가장 감사 할 것입니다.
당신은 로그 맵에이 있고'column'과'foreign-keys'는 모두 UserId로 명명됩니다. 이 올바른지? –
Rippo
나는 여러 가지 방법을 시도했다. (외래 키를 전혀 언급하지 않고, 칼럼에 주목하지 않고 ...) 차이를 만드는 것처럼 보이지 않았다. –