views:

142

answers:

2

Hi

I'm using the LinqtoSQL for a WPF M-V-VM application, as I might want to change from LinqtoSql to something else in the future, like Entity framework or Subsonic etc, thus I found repository pattern to be helpful,

My question is how do I create the model classes, suppose I have an table in the database, I understand that I cannot use the LINQtoSQL generated Class as the model class, if I do, then I would become dependent on LinqtoSQL, which inturn would take away the independence that I would have of implementing the repository pattern, does that mean that I would need to have my own custom classes for all entity classes?

+1  A: 

Yes, it means that you need to implement you own custom classes for all entity classes. It's a pain, but that's the current state of things.

See this SO answer for more information on the subject, and some possible remedies.

Mark Seemann
"don't let the name of the generated L2S classes fool you." fits in perfectly, I also see that it would be better to write your custom classes offering you benefits like one could manage all the validation logic in that custom class, to point out one thing.
81967
+2  A: 

Good lord, no. Why would you do that to yourself?

You've already got to duplicate so much in your ViewModels, why would you add another layer of duplication for so little gain, especially considering L2S can use plain ol' clr types?

I consider both my service contracts from WCF services and ORM types to be my model. Just because it doesn't reside in a *.Model namespace doesn't mean a thing.

If you feel like you need this lubricating layer, let that layer be your ViewModels. That's what they are there for.

Anderson Imes
I think I get what you are saying, put the ORM and services in the models and yeah... I too am a bit stunned by the amount of duplication that is going on here, will surely look into this, and let you know,, thanks Andy....
81967
Thanks Again for your concern to ask again :)
81967
and btw, it would have been real pains to duplicate the Model classes ... you saved me a lot of time,,,
81967