Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

do I need a class for every table for my db?

Tags:

c#

linq

im trying to grasp LINQ as I understand it LINQ will be your DAL to your db which in turn creates for you automatically a class that maps out your db structure for you and then you can perform queries using that class ..

  • im trying to do a function that would return the result of my LINQ queries ..
    • all the examples i have been reading seems to point that if I want my queries to be a defined type I have to create a specific class for it and used it as List ..

am I correct in my assumption ?? please do enlighten me

like image 358
Dennis Avatar asked Sep 01 '25 03:09

Dennis


2 Answers

"Linq" is not an ORM technology, it is simply a way to write query like statements inside of .Net languages. You have not said whether you are using Ling to SQL or Linq to Entities, which are both ORM technolgies that work with Linq to map your data schema to tables.

Linq to SQL will provide you with a straight mapping of every table to a class, and will handle most of the lifting to get this done. Your queries can return these types, or using your Linq expression you can "project" these types to other types that you have made yourself.

If you need more flexibility, Entity Framework will allow you to map a single table to multiple entities, multiple tables to a single entity, etc. To do this you have to do a lot more work on your own, since you have to modify the mapping by hand in many cases. Similar to Linq to SQL, queries can return either these generated types or specify their own types in query.

like image 79
Chris Pitman Avatar answered Sep 02 '25 17:09

Chris Pitman


By default, the Linq to SQL designer will create a class for each table in your database. The database context object that is created will have a definition for each table in your database. You can execute Linq queries against those table definitions and store the results in the generated classes, you have your queries generate anonymous types. It's up to you.

like image 29
Randy Minder Avatar answered Sep 02 '25 17:09

Randy Minder