linq to SQLite
https://www.devart.com/dotconnect/sqlite/articles/tutorial_linq.html
LINQ to SQLite TutorialThis tutorial guides you through the process of creating a simple application powered byLinqConnecttechnology. In less than 5 minutes you will have a ready-to-use data access layer for your business objects. In this walkthrough:
Introducing the LinqConnect (LINQ to SQLite) TechnologyLinqConnect (formerly known as LINQ to SQLite) is the fast and lightweight ORM solution,which is closely compatible to Microsoft LINQ to SQL and contains its own advanced features,such as complex type support,advanced data fetching options,configurable compiled query caching,and others. LINQ stands for Language-Integrated Query,which means that data retrieval is no longer a separate language. The LINQ engine allows .NET applications to connect to databases without bothering much about columns and rows. The data you receive is automatically formed as objects ready to use by your business logic. LINQ to Relational Data may be thought of as an object-relational mapping (ORM) tool. The type-safe LINQ queries get compiled into MSIL on the fly,and the query clauses are translated into SQL and sent to SQLite database for execution. This makes your data access layer safer,faster,and greatly more convenient to design. Requirements In this tutorial it is assumed that you already have the database objects created. You have to execute a script from the following file installed by default to Preparing the ProjectCreate a new console application in Visual Studio. It could be any other project type as well,but for simplicity's sake we'll use console project throughout the tutorial. The rest of the tutorial assumes that the name of the project isConsoleApplication1. If you project is named otherwise,you will have to substitute this name with the actual one in Solution Explorer. Generating Model from Database
The model you've just generated is ready to use. Entity Developer creates classes for all selected tables that represent entities. It also creates a descendant ofDevart.Data.Linq.DataContextclass,which controls the connection to the database,and the whole data flow. This class includes properties and methods named after your database objects. You will use these members to retrieve and modify data in the context. The generated code is contained in the file DataContext1.Designer.cs (DataContext1.Designer.vb). You may write your own partial classes and methods for it in the file DataContext1.cs (DataContext1.vb). Querying DataAll LINQ to SQLite operations are executed through the DataContext descendant,which is namedCrmDemoDataContextin this tutorial. To retrieve data you have to first create an instance of the context,then prepare a query withLinqConnect,and then access the object returned by the query,which may be a collection of objects or a single object. Let's read all the data from the table Company,sort it by CompanyID,and output some columns. Add the following block of code to the method Main: C# |