F. .edmx ファイルの使用
.edmx ファイルは XML ファイルで、エンティティ データ モデル(EDM:Entity Data Model)の定義と、ターゲット データベースのスキーマの記述、そして、その EDM とデータベース間のマッピングの定義を行います。.edmx ファイルには、ADO.NET Entity Data Model デザイナー(エンティティ デザイナー)で使用される、モデルを視覚的に表示するための情報も含まれています。
以下のコード例では、EDM レイヤーに Extended Entity Framework の機能を提供するために、.edmx ファイルに加える必要のある変更を示します。
Entity Framework には、ADO.NET と類似した一連のメソッドが含まれています。これらのメソッドは、LINQ、EntitySQL、および ObjectServices などの新しい Entity Framework コンシューマーで利用できるように適応させてあります。
ADO.NET Entity Framework データ プロバイダーは、PsqlStatus および PsqlConnectionStatistics エンティティを公開することによって、EDM のこの機能をモデル化します。これにより、Visual Studio の標準ツールを使用して、この機能をモデル化することが可能となります。
コード例
次のコードは、SSDL モデルの一例です。
<!--
SSDL content
-->
<edmx:StorageModels>
<Schema Namespace="DDTek.Store" Alias="Self" Provider="DDTek.Oracle" ProviderManifestToken="11g"
xmlns:store="https://schemas.microsoft.com/ado/2007/12/edm/ EntityStoreSchemaGenerator"
xmlns= "https://schemas.microsoft.com/ado/2006/04/edm/ssdl">
<EntityContainer Name="DDTek_Connection">
<EntitySet Name="Connection_Statistics" EntityType="DDTek.Store.Connection_Statistics" />
<EntitySet Name="Status" EntityType="DDTek.Store.Status" />
</EntityContainer>
<Function Name="RetrieveStatistics" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="false" ParameterTypeSemantics="AllowImplicitConversion" StoreFunctionName=""DDTek_Connection_RetrieveStatistics"" />
<Function Name="EnableStatistics" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="false" ParameterTypeSemantics="AllowImplicitConversion" StoreFunctionName=""DDTek_Connection_EnableStatistics"" />
<Function Name="DisableStatistics" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="false" ParameterTypeSemantics="AllowImplicitConversion" StoreFunctionName=""DDTek_Connection_DisableStatistics"" />
<Function Name="ResetStatistics" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="false" ParameterTypeSemantics="AllowImplicitConversion" StoreFunctionName=""DDTek_Connection_ResetStatistics"" />
<!--
<Function Name="Reauthenticate" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="false" ParameterTypeSemantics="AllowImplicitConversion" StoreFunctionName=""DDTek_Connection_Reauthenticate""> -->
<!-- <Parameter Name="CurrentUser" Type="varchar2" Mode="In" /> -->
<!-- <Parameter Name="CurrentPassword" Type="varchar2" Mode="In" /> -->
<!-- <Parameter Name="CurrentUserAffinityTimeout" Type="number" Precision="10" Mode="In" /> --></Function>
-->
<EntityType Name="Connection_Statistics">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="SocketReadTime" Type="binary_double" Nullable="false" />
<Property Name="MaxSocketReadTime" Type="binary_double" Nullable="false" />
<Property Name="SocketReads" Type="number" Precision="20" Nullable="false" />
<Property Name="BytesReceived" Type="number" Precision="20" Nullable="false" />
<Property Name="MaxBytesPerSocketRead" Type="number" Precision="20" Nullable="false" />
<Property Name="SocketWriteTime" Type="binary_double" Nullable="false" />
<Property Name="MaxSocketWriteTime" Type="binary_double" Nullable="false" />
<Property Name="SocketWrites" Type="number" Precision="20" Nullable="false" />
<Property Name="BytesSent" Type="number" Precision="20" Nullable="false" />
<Property Name="MaxBytesPerSocketWrite" Type="number" Precision="20" Nullable="false" />
<Property Name="TimeToDisposeOfUnreadRows" Type="binary_double" Nullable="false" />
<Property Name="SocketReadsToDisposeUnreadRows" Type="number" Precision="20" Nullable="false" />
<Property Name="BytesRecvToDisposeUnreadRows" Type="number" Precision="20" Nullable="false" />
<Property Name="IDUCount" Type="number" Precision="20" Nullable="false" />
<Property Name="SelectCount" Type="number" Precision="20" Nullable="false" />
<Property Name="StoredProcedureCount" Type="number" Precision="20" Nullable="false" />
<Property Name="DDLCount" Type="number" Precision="20" Nullable="false" />
<Property Name="PacketsReceived" Type="number" Precision="20" Nullable="false" />
<Property Name="PacketsSent" Type="number" Precision="20" Nullable="false" />
<Property Name="ServerRoundTrips" Type="number" Precision="20" Nullable="false" />
<Property Name="SelectRowsRead" Type="number" Precision="20" Nullable="false" />
<Property Name="StatementCacheHits" Type="number" Precision="20" Nullable="false" />
<Property Name="StatementCacheMisses" Type="number" Precision="20" Nullable="false" />
<Property Name="StatementCacheReplaces" Type="number" Precision="20" Nullable="false" />
<Property Name="StatementCacheTopHit1" Type="number" Precision="20" Nullable="false" />
<Property Name="StatementCacheTopHit2" Type="number" Precision="20" Nullable="false" />
<Property Name="StatementCacheTopHit3" Type="number" Precision="20" Nullable="false" />
<Property Name="PacketsReceivedPerSocketRead" Type="binary_double" Nullable="false" />
<Property Name="BytesReceivedPerSocketRead" Type="binary_double" Nullable="false" />
<Property Name="PacketsSentPerSocketWrite" Type="binary_double" Nullable="false" />
<Property Name="BytesSentPerSocketWrite" Type="binary_double" Nullable="false" />
<Property Name="PacketsSentPerRoundTrip" Type="binary_double" Nullable="false" />
<Property Name="PacketsReceivedPerRoundTrip" Type="binary_double" Nullable="false" />
<Property Name="BytesSentPerRoundTrip" Type="binary_double" Nullable="false" />
<Property Name="BytesReceivedPerRoundTrip" Type="binary_double" Nullable="false" />
<!--
Oracle specific
-->
<Property Name="PartialPacketShifts" Type="number" Precision="20" Nullable="false" />
<Property Name="PartialPacketShiftBytes" Type="number" Precision="20" Nullable="false" />
<Property Name="MaxReplyBytes" Type="number" Precision="20" Nullable="false" />
<Property Name="MaxReplyPacketChainCount" Type="number" Precision="20" Nullable="false" />
<Property Name="Id" Type="number" Precision="10" Nullable="false" />
</EntityType>
<EntityType Name="Status">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="ServerVersion" Type="varchar2" Nullable="false" />
<Property Name="Host" Type="varchar2" Nullable="false" />
<Property Name="Port" Type="number" Precision="10" Nullable="false" />
<Property Name="SID" Type="varchar2" Nullable="false" />
<!-- <Property Name="CurrentUser" Type="varchar2" Nullable="false" /> -->
<!-- <Property Name="CurrentUserAffinityTimeout" Type="number" Precision="10" Nullable="false" /> -->
<!-- <Property Name="SessionId" Type="number" Precision="10" Nullable="false" /> -->
<Property Name="StatisticsEnabled" Type="number" Precision="1" Nullable="false" />
<Property Name="Id" Type="number" Precision="10" Nullable="false" />
</EntityType>
</Schema>
</edmx:StorageModels>
モデルをさらに分解して、概念レイヤーで CSDL モデルを確立します。このレイヤーは EDM に公開されています。
<edmx:ConceptualModels>
<Schema Namespace="DDTek" Alias="Self"
xmlns="https://schemas.microsoft.com/ado/ 2006/04/edm">
<EntityContainer Name="DDTekConnectionContext">
<EntitySet Name="DDTekConnectionStatistics" EntityType="DDTek.DDTekConnectionStatistics" />
<EntitySet Name="DDTekStatus" EntityType="DDTek.DDTekStatus" />
<FunctionImport Name="RetrieveStatistics" EntitySet="DDTekConnectionStatistics" ReturnType= "Collection(DDTek.DDTekConnectionStatistics)" />
<FunctionImport Name="EnableStatistics" EntitySet="DDTekStatus" ReturnType="Collection(DDTek.DDTekStatus)" />
<FunctionImport Name="DisableStatistics" EntitySet="DDTekStatus" ReturnType= "Collection(DDTek.DDTekStatus)" />
<FunctionImport Name="ResetStatistics" EntitySet="DDTekStatus" ReturnType="Collection(DDTek.DDTekStatus)" />
<FunctionImport Name="Reauthenticate" EntitySet="DDTekStatus" ReturnType= "Collection(DDTek.DDTekStatus)">
<Parameter Name="CurrentUser" Type="String" />
<Parameter Name="CurrentPassword" Type="String" />
<Parameter Name="CurrentUserAffinityTimeout" Type="Int32" />
</FunctionImport>
</EntityContainer>
<EntityType Name="DDTekConnectionStatistics">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="SocketReadTime" Type="Double" Nullable="false" />
<Property Name="MaxSocketReadTime" Type="Double" Nullable="false" />
<Property Name="SocketReads" Type="Int64" Nullable="false" />
<Property Name="BytesReceived" Type="Int64" Nullable="false" />
<Property Name="MaxBytesPerSocketRead" Type="Int64" Nullable="false" />
<Property Name="SocketWriteTime" Type="Double" Nullable="false" />
<Property Name="MaxSocketWriteTime" Type="Double" Nullable="false" />
<Property Name="SocketWrites" Type="Int64" Nullable="false" />
<Property Name="BytesSent" Type="Int64" Nullable="false" />
<Property Name="MaxBytesPerSocketWrite" Type="Int64" Nullable="false" />
<Property Name="TimeToDisposeOfUnreadRows" Type="Double" Nullable="false" />
<Property Name="SocketReadsToDisposeUnreadRows" Type="Int64" Nullable="false" />
<Property Name="BytesRecvToDisposeUnreadRows" Type="Int64" Nullable="false" />
<Property Name="IDUCount" Type="Int64" Nullable="false" />
<Property Name="SelectCount" Type="Int64" Nullable="false" />
<Property Name="StoredProcedureCount" Type="Int64" Nullable="false" />
<Property Name="DDLCount" Type="Int64" Nullable="false" />
<Property Name="PacketsReceived" Type="Int64" Nullable="false" />
<Property Name="PacketsSent" Type="Int64" Nullable="false" />
<Property Name="ServerRoundTrips" Type="Int64" Nullable="false" />
<Property Name="SelectRowsRead" Type="Int64" Nullable="false" />
<Property Name="StatementCacheHits" Type="Int64" Nullable="false" />
<Property Name="StatementCacheMisses" Type="Int64" Nullable="false" />
<Property Name="StatementCacheReplaces" Type="Int64" Nullable="false" />
<Property Name="StatementCacheTopHit1" Type="Int64" Nullable="false" />
<Property Name="StatementCacheTopHit2" Type="Int64" Nullable="false" />
<Property Name="StatementCacheTopHit3" Type="Int64" Nullable="false" />
<Property Name="PacketsReceivedPerSocketRead" Type="Double" Nullable="false" />
<Property Name="BytesReceivedPerSocketRead" Type="Double" Nullable="false" />
<Property Name="PacketsSentPerSocketWrite" Type="Double" Nullable="false" />
<Property Name="BytesSentPerSocketWrite" Type="Double" Nullable="false" />
<Property Name="PacketsSentPerRoundTrip" Type="Double" Nullable="false" />
<Property Name="PacketsReceivedPerRoundTrip" Type="Double" Nullable="false" />
<Property Name="BytesSentPerRoundTrip" Type="Double" Nullable="false" />
<Property Name="BytesReceivedPerRoundTrip" Type="Double" Nullable="false" />
<Property Name="PartialPacketShifts" Type="Int64" Nullable="false" />
<Property Name="PartialPacketShiftBytes" Type="Int64" Nullable="false" />
<Property Name="MaxReplyBytes" Type="Int64" Nullable="false" />
<Property Name="MaxReplyPacketChainCount" Type="Int64" Nullable="false" />
<Property Name="Id" Type="Int32" Nullable="false" />
</EntityType>
<EntityType Name="DDTekStatus">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="ServerVersion" Type="String" Nullable="false" />
<Property Name="Host" Type="String" Nullable="false" />
<Property Name="Port" Type="Int32" Nullable="false" />
<Property Name="SID" Type="String" Nullable="false" />
<Property Name="CurrentUser" Type="String" Nullable="false" />
<Property Name="CurrentUserAffinityTimeout" Type="Int32" Nullable="false" />
<Property Name="SessionId" Type="Int32" Nullable="false" />
<Property Name="StatisticsEnabled" Type="Boolean" Nullable="false" />
<Property Name="Id" Type="Int32" Nullable="false" />
</EntityType>
</Schema>
</edmx:ConceptualModels>
次の単純なマッピングは、各部分を結び付けます。
<!--
C-S mapping content
-->
<edmx:Mappings>
<Mapping Space="C-S"
xmlns="urn:schemas-microsoft- com:windows:storage:mapping:CS">
<EntityContainerMapping StorageEntityContainer="DDTek_Connection" CdmEntityContainer="DDTekConnectionContext">
<EntitySetMapping Name="DDTekConnectionStatistics">
<EntityTypeMapping TypeName="DDTek.DDTekConnectionStatistics">
<MappingFragment StoreEntitySet="Connection_Statistics">
<!--
StoreEntitySet="Connection_Statistics" TypeName="DDTek.DDTekConnectionStatistics">
-->
<ScalarProperty Name="SocketReadTime" ColumnName="SocketReadTime" />
<ScalarProperty Name="MaxSocketReadTime" ColumnName="MaxSocketReadTime" />
<ScalarProperty Name="SocketReads" ColumnName="SocketReads" />
<ScalarProperty Name="BytesReceived" ColumnName="BytesReceived" />
<ScalarProperty Name="MaxBytesPerSocketRead" ColumnName="MaxBytesPerSocketRead" />
<ScalarProperty Name="SocketWriteTime" ColumnName="SocketWriteTime" />
<ScalarProperty Name="MaxSocketWriteTime" ColumnName="MaxSocketWriteTime" />
<ScalarProperty Name="SocketWrites" ColumnName="SocketWrites" />
<ScalarProperty Name="BytesSent" ColumnName="BytesSent" />
<ScalarProperty Name="MaxBytesPerSocketWrite" ColumnName="MaxBytesPerSocketWrite" />
<ScalarProperty Name="TimeToDisposeOfUnreadRows" ColumnName="TimeToDisposeOfUnreadRows" />
<ScalarProperty Name="SocketReadsToDisposeUnreadRows" ColumnName= "SocketReadsToDisposeUnreadRows" />
<ScalarProperty Name="BytesRecvToDisposeUnreadRows" ColumnName="BytesRecvToDisposeUnreadRows" />
<ScalarProperty Name="IDUCount" ColumnName="IDUCount" />
<ScalarProperty Name="SelectCount" ColumnName="SelectCount" />
<ScalarProperty Name="StoredProcedureCount" ColumnName="StoredProcedureCount" />
<ScalarProperty Name="DDLCount" ColumnName="DDLCount" />
<ScalarProperty Name="PacketsReceived" ColumnName="PacketsReceived" />
<ScalarProperty Name="PacketsSent" ColumnName="PacketsSent" />
<ScalarProperty Name="ServerRoundTrips" ColumnName="ServerRoundTrips" />
<ScalarProperty Name="SelectRowsRead" ColumnName="SelectRowsRead" />
<ScalarProperty Name="StatementCacheHits" ColumnName="StatementCacheHits" />
<ScalarProperty Name="StatementCacheMisses" ColumnName="StatementCacheMisses" />
<ScalarProperty Name="StatementCacheReplaces" ColumnName="StatementCacheReplaces" />
<ScalarProperty Name="StatementCacheTopHit1" ColumnName="StatementCacheTopHit1" />
<ScalarProperty Name="StatementCacheTopHit2" ColumnName="StatementCacheTopHit2" />
<ScalarProperty Name="StatementCacheTopHit3" ColumnName="StatementCacheTopHit3" />
<ScalarProperty Name="PacketsReceivedPerSocketRead" ColumnName="PacketsReceivedPerSocketRead" />
<ScalarProperty Name="BytesReceivedPerSocketRead" ColumnName="BytesReceivedPerSocketRead" />
<ScalarProperty Name="PacketsSentPerSocketWrite" ColumnName="PacketsSentPerSocketWrite" />
<ScalarProperty Name="BytesSentPerSocketWrite" ColumnName="BytesSentPerSocketWrite" />
<ScalarProperty Name="PacketsSentPerRoundTrip" ColumnName="PacketsSentPerRoundTrip" />
<ScalarProperty Name="PacketsReceivedPerRoundTrip" ColumnName="PacketsReceivedPerRoundTrip" />
<ScalarProperty Name="BytesSentPerRoundTrip" ColumnName="BytesSentPerRoundTrip" />
<ScalarProperty Name="BytesReceivedPerRoundTrip" ColumnName="BytesReceivedPerRoundTrip" />
<ScalarProperty Name="PartialPacketShifts" ColumnName="PartialPacketShifts" />
<ScalarProperty Name="PartialPacketShiftBytes" ColumnName="PartialPacketShiftBytes" />
<ScalarProperty Name="MaxReplyBytes" ColumnName="MaxReplyBytes" />
<ScalarProperty Name="MaxReplyPacketChainCount" ColumnName="MaxReplyPacketChainCount" />
<ScalarProperty Name="Id" ColumnName="Id" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
<EntitySetMapping Name="DDTekStatus">
<EntityTypeMapping TypeName="DDTek.DDTekStatus">
<MappingFragment StoreEntitySet="Status">
<ScalarProperty Name="ServerVersion" ColumnName="ServerVersion" />
<ScalarProperty Name="Host" ColumnName="Host" />
<ScalarProperty Name="Port" ColumnName="Port" />
<ScalarProperty Name="SID" ColumnName="SID" />
<!-- <ScalarProperty Name="CurrentUser" ColumnName="CurrentUser" /> -->
<!-- <ScalarProperty Name="CurrentUserAffinityTimeout" ColumnName="CurrentUserAffinityTimeout" /> -->
<!-- <ScalarProperty Name="SessionId" ColumnName="SessionId" /> -->
<ScalarProperty Name="StatisticsEnabled" ColumnName="StatisticsEnabled" />
<ScalarProperty Name="Id" ColumnName="Id" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
<FunctionImportMapping FunctionImportName="RetrieveStatistics" FunctionName= "DDTek.Store.RetrieveStatistics" />
<FunctionImportMapping FunctionImportName="EnableStatistics" FunctionName="DDTek.Store.EnableStatistics" />
<FunctionImportMapping FunctionImportName="DisableStatistics" FunctionName= "DDTek.Store.DisableStatistics" />
<FunctionImportMapping FunctionImportName="ResetStatistics" FunctionName="DDTek.Store.ResetStatistics" />
<FunctionImportMapping FunctionImportName="Reauthenticate" FunctionName= "DDTek.Store.Reauthenticate" />
</EntityContainerMapping>
</Mapping>
</edmx:Mappings>
 
最終更新日: 2024年07月16日