0

次のような CodeFluent エンティティ モデルがあります。

<cf:project defaultNamespace="S5T" xmlns:cf="http://www.softfluent.com/codefluent/2005/1" xmlns:cfx="http://www.softfluent.com/codefluent/modeler/2008/1" xmlns:cfmy="http://www.softfluent.com/codefluent/producers.mysql/2012/1" xmlns:cfom="http://www.softfluent.com/codefluent/producers.model/2005/1" xmlns:cfasp="http://www.softfluent.com/codefluent/producers.aspnet/2011/1" xmlns:cfaz="http://www.softfluent.com/codefluent/producers.sqlazure/2011/1" xmlns:cfps="http://www.softfluent.com/codefluent/producers.sqlserver/2005/1" defaultKeyPropertyTypeName="long" maxParameterNameLength="62" defaultConcurrencyMode="None" persistencePropertyNameFormat="{1}" defaultMethodAllowDynamicSort="false" defaultProducerProductionFlags="Default, Overwrite, RemoveDates" defaultMethodDistinct="false" createDefaultMethodForms="true" createDefaultApplication="false" createDefaultHints="false" productionFlags="Default, Overwrite, RemoveDates">
  <cf:import path="Default.Surface.cfp" />
  <cf:producer name="SQL Server" typeName="CodeFluent.Producers.SqlServer.SqlServerProducer, CodeFluent.Producers.SqlServer">
    <cf:configuration produceViews="true" targetDirectory="..\Model7Bom\Persistence" connectionString="Server=MY-MACHINE\SQLEXPRESS;Database=model7;Integrated Security=true;Application Name=S5T;Password=MyPassword;User ID=MyUser" cfx:targetProject="..\Model7Bom\Model7Bom.vbproj" cfx:targetProjectLayout="Update, DontRemove" />
  </cf:producer>
  <cf:entity name="User" namespace="S5T">
    <cf:property name="Id" key="true" cfps:hint="CLUSTERED" />
    <cf:property name="Name" />
    <cf:property name="Roles" typeName="{0}.RoleCollection" relationPropertyName="Users" />
  </cf:entity>
  <cf:entity name="Role" namespace="S5T">
    <cf:property name="Id" key="true" cfps:hint="CLUSTERED" />
    <cf:property name="Name" />
    <cf:property name="Users" typeName="{0}.UserCollection" relationPropertyName="Roles" />
  </cf:entity>
</cf:project>

cfps:hint="CLUSTERED" を使用して、両方のエンティティでcf:property name="Id"を正常に装飾でき ました。これにより、Sql Serverプロデューサーが正しく出力できるようになりました

CONSTRAINT [PK_Use_Id_Use] PRIMARY KEY CLUSTERED
CONSTRAINT [PK_Rol_Id_Rol] PRIMARY KEY CLUSTERED

デフォルトの NONCLUSTERED とは対照的です。

多対多の関係に対応するために、モデルによって生成された THIRD TABLE を使用してそれを達成するにはどうすればよいですか?

デフォルトでは、テーブル作成によって生成されるスニペットは次のようになります。

CREATE TABLE [dbo].[Role_Users_User_Roles] (
 [Id] [bigint] NOT NULL,
 [Id2] [bigint] NOT NULL,
 CONSTRAINT [PK_Roe_Id_Id2_Roe] PRIMARY KEY NONCLUSTERED
 (

  [Id],
  [Id2]
 ) ON [PRIMARY]
)

ただし、両方のプロパティを cfps:hint="CLUSTERED" で装飾すると、次のようになります。

cf:property name="Roles" typeName="{0}.RoleCollection" relationshipPropertyName="Users" cfps:hint="CLUSTERED" /

cf:property name="Users" typeName="{0}.UserCollection" relationshipPropertyName="Roles" cfps:hint="CLUSTERED" /

TABLE [dbo].[Role_Users_User_Roles] の PK に対して PRIMARY KEY CLUSTERED で生成されたスニペットを取得しますが、さらに、リレーションを追加するために誤ったスクリプトが生成されるという望ましくない効果があります (生成されたファイル名 ...relations_add.sql )、 そのような:

ALTER TABLE [dbo].[Role_Users_User_Roles] WITH NOCHECK ADD CONSTRAINT [FK_Roe_Id_Id_Rol] FOREIGN KEY (
 [Id]
) REFERENCES [dbo].[Role](

 [Id]
) CLUSTERED

Sql Server からのエラーとともに:

エラー 3 SQL80001: 'CLUSTERED' 付近の構文が正しくありません。

CodeFluent プロデューサー エラー:

CodeFluentRuntimeDatabaseException: CF4116: 2 行目の file ...path..._relations_add.sql ステートメントの実行

生成された 3 つのテーブルで 3 つの PK がすべてクラスター化されている必要がありますが、関係を生成するための構文エラーの副作用は必要ありません。

4

1 に答える 1