Knight Data Access Layer
Loading with LINQ
Basic Tasks C# > Loading Data > Loading with LINQ

 

Knight Data Access Layer contains built in LINQ providers for SQL Server, MS Access, Oracle, Firebird, VistaDB, Sqlite, and MySQL. It supports all standard LINQ select expressions including:

 

//Create a new Person to save to the database

Person person = new Person

{

FirstName = "Greg",

LastName = "Smith",

DateCreated = DateTime.Now.Date

};

 

//Get the current instance of the helper

IDataHelper db = DataHelper.SessionFactory();

 

//Save it

db.Save(person);

 

var query = db.CreateQuery<Person>();

var persons = query.Where(o => o.FirstName == "Greg");

 

//Other examples
var persons = query.Where(o => o.FirstName.Contains("Greg"));
var persons = query.Where(o => o.FirstName.StartsWith("Greg"));
var persons = query.Where(o => o.DateCreated < DateTime.Today);