none
Do i have to know LINQ to SQL and Entity framework to write a DB application with WCF? RRS feed

  • Question

  • hi,

    When i read all books on WCF and when the application needs to access DB, WCF uses LINQ to SQL and Entity framework to do CRUD operations. But what if some one wants to write CRUD operations with ADO .NET, does WCF support writing ADO .NET CRUD operation without LINQ to SQL and Entity framework?

    Are there any issues to use ADO .NET with WCF?

    thnaks


    I use Visual studio 2010 Ultimate and SQL server 2008 developer edition!

    Friday, July 4, 2014 2:06 PM

Answers

  • When i read all books on WCF and when the application needs to access DB, WCF uses LINQ to SQL and Entity framework to do CRUD operations. But what if some one wants to write CRUD operations with ADO .NET, does WCF support writing ADO .NET CRUD operation without LINQ to SQL and Entity framework?

    Are there any issues to use ADO .NET with WCF?

    WCF is about SOA and communications between client and the service client/service communications.

    http://en.wikipedia.org/wiki/Service-oriented_architecture

    http://msdn.microsoft.com/en-us/library/aa480021.aspx

    http://msdn.microsoft.com/en-us/library/ms731082(v=vs.110).aspx

    WCF has nothing to do with database access and CRUD operations, because again WCF is SOA and communications between the client and service. The database could be MS Access, Oracle, MS SQL Server or many other databases the could be sitting behind the WCF service. It could be EF, Linq-2-SQL,  nHibernate as the ORM solution sitting behind the WCF service. All of the mentioned database technology solutions are using ADO.NET.

    Therefore, ADO.NET is being used and ADO.NET can be used directly against any database that has an ADO.NET provider like MS, Oracle etc etc that provides the database drivers used by ADO.NET. So you don't need Linq-2-SQL, nHibernate, EF or any ORM period sitting behind a WCF service and doing CRUD. And you can use ADO.NET SQL command objects with in-line T-SQL or sprocs for CRUD operations with the database, or you can use ADO.NET with Oracle command objects and in-line P-SQL or Oracle Packages (like sprocs in MS-SQL-Sever) CRUD or whatever a database provider has for ADO.NET.

    This is normally done by a classlib project called a DAL or a Repository sitting behind the WCF service that the WCF service has reference to that has the CRUD methods that WCF will call upon. Even if you were using an ORM, then the CRUD methods to use the ORM would be in a DAL or Repository that the WCF service has reference to.

    If not using an ORM or even if you are using one, then how do you get data passed between the WCF client and WCF service. You would be using DTO(s) as DataContracts, which is what WCF expects.

    http://en.wikipedia.org/wiki/Data_transfer_object

    http://msdn.microsoft.com/en-us/library/ms733811(v=vs.110).aspx

    The DTO(s) would be using auto-properties.

    http://msdn.microsoft.com/en-us/library/bb384054.aspx

    http://msdn.microsoft.com/en-us/library/dd293589.aspx

    The DtoPerson using auto-properties as a [DataContract] would have a [Datamember] above each auto-property in the DTO.

    The DTO(s) would be in a classlib project call it Entities, and the WCF client and WCF service project would have reference to Entities  and know what the DTO(s) are about.

    Of course, you would have to map data between the data-stor and the DTO(s) to send them to the client, and you have to map DTO(s) to that data-stor to persist data to the database-stor.

    If you were using EF, then you can use Entity2DTO, because they are implicit Datacontracts to WCF.

    http://entitiestodtos.codeplex.com/

    EF Entities on the EF model are Datacontracts too, but one doesn't send EF Entities through WCF. One sends the DTO(s).

    • Marked as answer by sniff_bits Saturday, July 5, 2014 2:34 AM
    Friday, July 4, 2014 3:17 PM