Search code examples
linqsqlmetal

sqlmetal.exe run and output generated but how do I query my database?


I have run sqlmetal.exe agaisnt my database.

SqlMetal.exe /server:server /database:dbname /code:mapping.cs

I have included this into my solution. So I can now create an object for each of the database tables. Great. I now wish to use ling to query by database. Can I presume that none of the connection etc is handled by the output of sqlmetal.exe. If this is correct what ways can I use ling to query my database?


Solution

  • Does the generated code include a Data Context (a class which inherits from System.Data.Linq.DataContext)? If so, then that's probably what you're looking for. Something like this:

    var db = new SomeDataContext();
    // You can also specify a connection string manually in the above constructor if you want
    var records = db.SomeTable.Where(st => st.id == someValue);
    // and so on...