How to move from LINQ to SQL to “LINQ to WCF”?

后端 未结 4 1181
自闭症患者
自闭症患者 2021-02-09 04:25

I\'m putting together a WPF application which will eventually use WCF web services as its data source.

During the prototyping phase, I\'m using LINQ to SQL on an SQL 200

相关标签:
4条回答
  • 2021-02-09 05:00

    You'll probably want ADO.NET Data Services. You'll have to add an IUpdatable interface implementation to your entities, and you can use LINQ to SQL, Entity Framework, SubSonic, or a number of others. We're using the CodeSmith PLINQO templates, which allow you to add this functionality to LINQ to SQL.

    0 讨论(0)
  • 2021-02-09 05:09

    A generic LINQ to WCF may not make sense. In particular, WCF calls only expose data in very specific ways, which doesn't really conform to the LINQ way of doing things. For example, my service could have the following contract:

    List<DAO> GetObjectsInDateRange(DateTime start, DateTime end);
    void ExportObjectsToLegacySystem(List<DAO> data);
    

    How do you express either in LINQ format. In particular, when start and end are not members of DAO. The only way to express it would be for the service to expose an IQueryable interface and I don't know how possible that is.

    Now, you can always do:

    var data = from dao 
    in wcfService.GetObjectsInDateRange(DateTime.Today,DateTime.Today.AddDays(50))
    where dao.AmountOfStuff > 20
    select dao;
    

    That being said, you can certainly create a LINQ interface tailored to your own service. Let's say your service has a method:

    List<DAO> GetObjects(DAOFilter filterObject);
    

    where the DAOFilter is an object that specifies all your "where" criteria, what you can do is write a LINQ provider that translates all the Expressions into this DAOFilter object. This would be an incredibly one-off solution with a considerable amount of work so I would advise against it.

    I echo the advice to take a look at ADO.Net Data Services.

    0 讨论(0)
  • 2021-02-09 05:10

    You can add a Linq to SQL class directly to a WCF project and set Serialization Mode on the Linq to SQL class to Unidirectional. If you do this the classes will show up over the WCF service.

    0 讨论(0)
  • 2021-02-09 05:12

    Have you had a look at ADO.NET Data services. Here you can query a data store over the wire with linq syntax.

    You'll keep the LINQ to SQL data context but expose it to the web and allow your clients to query the context in standard LINQ statements. You would obviously have to secure the Data Services so only authorised clients can connect but essentially with minimal work you are able to get your data context "client side" so to speak.

    0 讨论(0)
提交回复
热议问题