Sqlite   发布时间:2022-05-19  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了linq to SQLite大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

https://www.devart.com/dotconnect/sqlite/articles/tutorial_linq.HTML





liNQ to SQLite tutorial

This 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) Technology
  • requirements
  • Preparing the Project
  • GeneraTing Model from Database
  • Querying Data
  • InserTing New Data
  • updating Data
  • deleting Data
  • Additional Information

Introducing the linqConnect (liNQ to sqlitE) Technology

linqConnect (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
\Program files\Devart\dotConnect\sqlite\Samples\crm_demo.sql

Preparing the Project

Create 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

  1. Add Devart linqConnect Model to the project. To do this,right-click on the project node in Solution Explorer,point toAdd,clickNew Item.... In theAdd New Itemdialog SELEctDatacategory,chooseDevart linqConnect Modeltemplate,and clickAdd. This automatically launches Create New Model wizard,which creates a new empty model or generates it from database.
  2. ClickNexton the welcome screen.
  3. Fill in connection setTings and clickNext.
  4. Choose database objects that will be used in the model. these are all objects from the crm_demo script,including auxiliary tables. ClickNext.
  5. On the next screen you can adjust naming rules for entitIEs and their members. For the CRM Demo database no rules are required,so just clickNext.
  6. inputCrmDemoContextas namespace,andCrmDemoDataContextas the name of DataContext descendant. This will be the name of the main data access class. ClickNext.
  7. PressFinish. The model will be generated and opened in Entity Developer.
  8. In the main menu,clickfile|Save. This updates the generatedCrmDemoDataContext@H_417_54@model code in Visual studio.

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 Data

All 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#
CrmDemoDataContext context = new CrmDemoDataContext();
var query = from it in context.CompanIEs
orderby it.CompanyId
SELEct it;
foreach (Company comp query)
Console.Writeline( "{0} | {1} | {2}" ,comp.CompanyId,comp.Companyname,comp.Country);
@H_772_199@
Console.Readline();
Visual Basic
Dim context As CrmDemoDataContext = New CrmDemoDataContext
query = From it In context.companIEs _
Order By it.CompanyId _
SELEct it
comp company
For Each query
@H_772_199@ Console.Writeline( @H_618_272@"{0} | {1} | {2}" Next
Console.Readline()

大佬总结

以上是大佬教程为你收集整理的linq to SQLite全部内容,希望文章能够帮你解决linq to SQLite所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: