it:ad:ef:modelfirst_ste_over_wcf

How's it's done:

  • Create a WCF app to host .svc endpoints Need to make a Model:
    • Add/New Item…/C#/Data/ADO.NET Entity Data Model
    • Follow through…
    • Result is “something.edmx”
  • Problems:
    • Models inherit from EF4 classes, not POCO
  • Solution:
    • Click on the Model's design surface (the whitepsace)
    • Select Add Cdoe Generation Item…
    • In order to select a more appropriate template:
      • C#/Data/ADO.NET Self Tracing Entity
        • Result is two T4 templates, one for Context, one for Entities

        * Remember that STE's are POCO's with a little bit more change tracking if the following are true:

    • Client must be .NET as well.
      • Share Entities

      * Add new 'shared' Assembly.

  • Add Needed Dependencies:
    • Add System.Runtime.Serialization.dll
    • WindowsBase (NET30) OR
  • Cut/Paste the ModelSTE.tt from first app assembly to new shared assembly.
    • BUG: If you try In Solution Explorer/Right-Click ModelSTE.tt/Run Custom Tool it will fail, due to ModelSTE.tt looking for *.edmx relative to it.
      • FIX:
        • editing modelSTE.tt to adjust path back to original *.edmx:
        `string inputFile= @"../Server.Assembly/Model.edmx";`
        *BUG: Entities might now build, but Context.tt might not as it can't find entities.
            * FIX: 
                * Add Ref from first assembly to second.
                * Ensure that `Custom Tool Namespace` is same in both *.tt files so it can resolve to ENtities.

        ## Testing ##

  • Make a client, point back to the server's service, give it a whirl.
  • When you build the client you have two options:
    • Not reuse the shared assemblies… But as change tracking was not serialized to the Proxy, you have to manually mark that changes were made:
`contact.Addresses[0].ChangeTracker.State = ObjectState.Modified;`
 
  * Reuse the shared assemblies: all goes swimmingly.

#

# Resources ##

  • /home/skysigal/public_html/data/pages/it/ad/ef/modelfirst_ste_over_wcf.txt
  • Last modified: 2023/11/04 22:24
  • by 127.0.0.1