Server - Client application and shared Linq to SQL generated classes

68 Views Asked by At

I'm working on a client-server application where server is running as REST service and is connected to SQL server. Classes are generated automatically from *.dbml file (LINQ->SQL).

My question is: Should I create new classes for data exchange between server and client or just use generated classes on both sides?

Using of the same classes generated from *.dbml - PROS

  1. Better sustainability (data constrains are generated automatically)

  2. Less probability of data errors caused by copying data between two data objects - (model is generated automatically and you don't have need to maintain copying of values from generated model to another)

  3. Better speed. You have to create only one instance of model on server.

    • (when you have class A and class B representing the same data you have to create instance of both classes)

Using of the same classes generated from *.dbml - CONS

  1. Client exactly know the db table structure and used datatypes
1

There are 1 best solutions below

0
On

One "CON" you're missing is that using the the same model could mean you're transferring more data than is needed.

Using specific contracts between the client and server would mean only data the client needs is sent over the wire.