Link to home
Create AccountLog in
Avatar of Camillia
CamilliaFlag for United States of America

asked on

How is using LINQ related to using classes like Abstract classes?

This is a related question. I have a Patient table and a Doctor table. Suppose they have something in common (as the answer to my related question suggests). So, I create a PatientClass, DoctorClass and I will also have an
abstract BaseClass.

Now, I'm using LINQ to get the data from Patients. For example, I load a patient information. PatientClass relates to a table in the database and I will use LINQ...

Now, do I need the abstract BaseClass?? OR does each class just relate to a table in the database when I use LINQ? No more OO with LINQ??
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Camillia


I've been looking for an example to show how OO works with LINQ and can't find one. For example, in this link below...are steps 10 and 11 correct? for some reason, I thought if i use LINQ, I don't need to use properties or private variables:

do you have an example that can show LINQ along with one OO concept inhertiance or an abstract class?
He is only doing steps 10 and 11 because he is calling a stored procedure rather than actually modelling the tables in the database. If he had modelled the tables instead then he would simply have created a new "Register" object and added that to the context.
Does having properties (get, set) in that example correct?
Also, >> have created a new "Register" object and added that to the context.

can you show me how?
Yes. The classes created as part of your model are basic data container classes with a properties that map to the columns in the underlying table.

So, as a simple example you might do something like:
// create a data context
NorthwindDataContext db = new NorthwindDataContext();

// create a new product
Product product = new Product();
product.Name = "Sample product";

// add to database

Open in new window

thanks so much. I have a coworker (he's the "architect") and said we dont need the properties, etc with LINQ. Thanks for clarifiying this.