Bienvenue à Blogs CodeS-SourceS Identification | Inscription | Aide

Matthieu MEZIL

I love .Net

Abonnements

TPH IS Not Null sur la relation

Comme je vous le disais précédemment, il y a, avec EF V1, une restriction sur le mapping obligatoire lorsqu'on utilise la condition Is Not Null : la mapping doit obligatoirement se faire sur une scalar property et non sur une navigation property.

Comment contourné cela ?

Avec une SSDL View bien sûr Wink

<EntitySet Name="CustomerContacts" EntityType="TestRelationshipsOnTPHModel.Store.CustomerContacts">

    <DefiningQuery>

        SELECT ContactId, CAST(CASE WHEN CustomerId IS NULL THEN 0 ELSE 1 END AS BIT) AS IsContactCustomer

        FROM Contacts

    </DefiningQuery>

</EntitySet>

<EntityType Name="CustomerContacts">

    <Key>

        <PropertyRef Name="ContactId" />

    </Key>

    <Property Name="ContactId" Type="int" Nullable="false" />

    <Property Name="IsContactCustomer" Type="bit" />

</EntityType>

Ensuite, il suffit de la mapper sur l'entity type dérivé CustomerContact ce qui nous donne le MSL suivant :

<edmx:Mappings>

    <Mapping Space="C-S" xmlns="urn:schemas-microsoft-com:windows:storage:mapping:CS">

        <EntityContainerMapping StorageEntityContainer="TestRelationshipsOnTPHModelStoreContainer" CdmEntityContainer="TestRelationshipsOnTPHEntities">

            <EntitySetMapping Name="Contacts">

                <EntityTypeMapping TypeName="IsTypeOf(TestRelationshipsOnTPHModel.Contact)">

                    <MappingFragment StoreEntitySet="Contacts">

                        <ScalarProperty Name="ContactName" ColumnName="ContactName" />

                        <ScalarProperty Name="ContactId" ColumnName="ContactId" />

                    </MappingFragment>

                </EntityTypeMapping>

                <EntityTypeMapping TypeName="IsTypeOf(TestRelationshipsOnTPHModel.CustomerContact)">

                    <MappingFragment StoreEntitySet="CustomerContacts" >

                        <ScalarProperty Name="ContactId" ColumnName="ContactId" />

                        <Condition ColumnName="IsContactCustomer" Value="true" />

                    </MappingFragment>

                </EntityTypeMapping>

            </EntitySetMapping>

            <EntitySetMapping Name="Customers">

                <EntityTypeMapping TypeName="IsTypeOf(TestRelationshipsOnTPHModel.Customer)">

                    <MappingFragment StoreEntitySet="Customers">

                        <ScalarProperty Name="CompanyName" ColumnName="CompanyName" />

                        <ScalarProperty Name="CustomerId" ColumnName="CustomerId" />

                    </MappingFragment>

                </EntityTypeMapping>

            </EntitySetMapping>

            <AssociationSetMapping Name="CustomerCustomerContact" TypeName="TestRelationshipsOnTPHModel.CustomerCustomerContact" StoreEntitySet="Contacts">

                <EndProperty Name="CustomerContact">

                    <ScalarProperty Name="ContactId" ColumnName="ContactId" />

                </EndProperty>

                <EndProperty Name="Customer">

                    <ScalarProperty Name="CustomerId" ColumnName="CustomerId" />

                </EndProperty>

                <Condition ColumnName="CustomerId" IsNull="false" />

            </AssociationSetMapping>

        </EntityContainerMapping>

    </Mapping>

</edmx:Mappings>

Ce post vous a plu ? Ajoutez le dans vos favoris pour ne pas perdre de temps à le retrouver le jour où vous en aurez besoin :

Publié vendredi 29 août 2008 08:15 par Matthieu MEZIL

Commentaires

Pas de commentaires

Les commentaires anonymes sont désactivés

Les 10 derniers blogs postés

- [Refactoring] ReSharper pour Visual Studio 2010 (Preview) par Thomas Jaskula le il y a 4 heures et 22 minutes

- [Refactoring] Analyser vos exceptions avec ReSharper Exceptional par Thomas Jaskula le il y a 5 heures et 36 minutes

- SharePoint 2007 : patterns & practices SharePoint Guidance par Philippe Sentenac [MVP SharePoint] le il y a 19 heures et 16 minutes

- [Visual Studio 2010] Les tests cases c’est bien, mais je vais devoir tout réécrire ? par Etienne Margraff le il y a 20 heures et 12 minutes

- MVP[Gribouillon].AddYear par The Grib's Lair [Sébastien PICAMELOT - MVP SharePoint] le il y a 20 heures et 27 minutes

- Clinique INSIA - Projet de fin d’Etudes (Silverlight 3 MVVM et OutOfBrowser, WCF, TFS) - Part 1 par David REI le 07-02-2009, 23:38

- C’est la crise ? Bah pourquoi cramer du budget pub alors ? par Nix's Blog le 07-02-2009, 15:31

- Soyons MVP ! par TheSaib .NET blog le 07-02-2009, 12:15

- SharePoint : Gestion des Erreurs 6398, 7076 et 6482 par Blog Technique de Romelard Fabrice le 07-02-2009, 11:53

- EF avec WPF par Matthieu MEZIL le 07-02-2009, 10:18