views:

160

answers:

2

As a simplified example, I have the following data classes:

public class Employee
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public Position Position { get; set; }
}

public class Position
{
    public string Title { get; set; }
    public string Description { get; set; }
    public decimal Salary { get; set; }
}

In the database (let's say Sql Server), I have the following tables:

Table: Employees
    Column: EmployeeID (unique, primary key)
    Column: FirstName
    Column: LastName
    Column: Positions_PositionID (foreign key)

Table: Positions
    Column: PositionID (unique, primary key)
    Column: Title
    Column: Salary

What options are available to me so that I can 'copy' the tables in the database into a, say, IQueryable<Employee> list?

+3  A: 

What you're looking for is a ORM layer. There are a number of tools out there, probably the quickest solution is to add a linq2sql data context. Just right click on the model folder and select LINQ to SQL Classes then drag your tables from the server explorer onto the canvas. It will generate all your data classes for you.

Other options are such thigs as subsonic and NHibernate

A more complete list can be found on the source of all human knowledge, wikipedia: http://en.wikipedia.org/wiki/List%5Fof%5Fobject-relational%5Fmapping%5Fsoftware#.NET

stimms
Thanks, that's what I was thinking. My only experience with Linq to SQL was having it auto-generate the classes for me, which doesn't work for my purposes.
Daniel T.
A: 

As stimms said you can use linqto sql as your ORM layer. Checkout this link to learn linq to sql

San