Installation

Installation is provided via NuGet. Search for LinqToOdbc in Visual Studio or refer to http://www.nuget.org/List/Packages/LinqToOdbc.

Example Usage

For current and supported usage samples, please refer to the Tests project in Source Code. A basic example follows.
  //
  // "View class" (Generated with the assistance of another app)
 //  Linq "Table" attribute is used to specified actual table
    [Table(Name = "Employees")]
    public class Employee {
        public int EmployeeID { get; set; }
        public string LastName { get; set; }
        public string FirstName { get; set; }
    }

 //   
 // Code that would be used generate/execute SQL and map to view
 // Variable 'resolver' is inteded to be an IoC container/ServiceLocator which provides an initialized instance of IOdbcQueryContext
  using (var ctx = resolver.Get<IOdbcQueryContext>()) {                 // Generally the context scope controls the connection to the database, allowing for multiple queries during one connection
      var query = from p in ctx.Queryable<Employee>()                   // References the view object via generic method call to Queryable<T>()
      where p.FirstName == "Nancy" && p.LastName == "Davolio"
      select p;
     var result = query.ToList();                                                        // Query is run against database upon call of ToList()
  }
Resulting SQL (may not be exact)
SELECT p.* 
FROM Employees p 
WHERE ((p.FirstName = 'Nancy') AND (p.LastName = 'Davolio'))

Last edited Oct 4, 2011 at 3:19 PM by kcourville, version 2

Comments

No comments yet.