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

后端 未结 4 1180
自闭症患者
自闭症患者 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: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 GetObjectsInDateRange(DateTime start, DateTime end);
    void ExportObjectsToLegacySystem(List 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 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.

提交回复
热议问题