Basic of simple. data and basic of simple. data

Source: Internet
Author: User

Basic of simple. data and basic of simple. data

Simple. data is a lightweight and dynamic data access component that supports. net4.0.

1. Required Conditions and dependencies:
  • V4.0 or greater of the. NET framework, or
  • V2.10 or greater of the Mono framework

Reference in Project

  • Simple. Data. Core
  • A Simple. Data adaptor
  • A Simple. Data provider

2. PM> Install-Package

Simple. Data. Oracle

Simple. Data. SqlServer

...

3. Open a connection

Var db = Database. OpenConnection ("connection string name ");

4. Naming rules

   

Exact match, case insensitive

5. CRUD operations

5.1 Insert (object or name parameter)

Db. Author. Insert (UserName: "123", FullName: "234", CreateDate: DateTime. Now );

5.2. Read

-All ()

-Find (simple expression)

-Get (primary key)

-FindAll (selection criteria)

-FindAllByXXX (parameter)

IEnumerable <dynamic> authors = db. Author. All ();

Var author = db. Author. FindAllByFullName ("234 ");

 

5.3. Update (object or named parameter)

-Update

-UpdateByXXX (parameter)

-UpdateAll (selection condition)

Db. Author. UpdateByUserName (UserName: "123", FullName: "2334 ");

 

5.4. Delete

-Delete (object or name parameter)

-DeleteByXXX (parameter)

-DeleteAll (selection criteria)

Db. Author. DeleteByUserName (UserName: "123 ");

6. Conversion

6.1 implicit conversion

Return a single result: var product = db. Product. Get (1 );

Return multiple results: var products = db. product. FindAllByFactoryName ("baogang ");

IEnumerable <dynamic> products = db. product. FindAllByFactoryName ("baogang ");

6.2 strong type conversion

IEnumerable <Product> products = db. product. FindAllByFactoryName ("baogang"). Cast <Product> ();

List <dynamic> products = db. product. FindAllByFactoryName ("baogang"). ToList ();

List <Product> products = db. product. FindAllByFactoryName ("baogang"). ToList <Product> ();

Product [] products = db. product. FindAllByFactoryName ("baogang"). ToArray <Product> ();

Dynamic [] products = db. product. FindAllByFactoryName ("baogang"). ToArray ();

7. Number of returned results

-GetCount

-GetCountBy

-Exists, Any

-ExistsBy, AnyBy

Var isFactoryExists = db. Product. Exists (FactoryName = "baogang ");

Var isFactoryExists = db. Product. Any (FactoryName = "baogang ");

Var factoryCount = db. Product. GetCount (FactoryName = "baogang ");

Var factoryCount = db. Product. GetCountBy (FactoryName: "baogang ");

Var isFactoryExists = db. Product. AnyBy (FactoryName: "baogang", FactoryName: "angang ");

8. query and modify

8.1. Returned result Column

Var products = db. Product. All (). Select (db. Product. ProductName );

Var products = db. Product. All (). Select (db. Product. AllColumns ());

8.2. deduplication

Var products = db. Product. All (). Select (db. Product. ProductName, db. Product. FactoryName. Distinct ());

8.3 column alias

Var products = db. Product. All (). Select (db. Product. ProductName. As ("Name "));

8.4. Filter

Var products = db. Product. All (). Where (FactoryName = "baogang ");

Var orderDetails = db. OrderDetail. All (). Where (db. OrderDetail. Price * db. OrderDetail. Quantity> 2000 );

Var products = db. product. All (). Where (db. Product. FactoryName = new [] [{"baogang", "angang"}); // in

Var orderDetails = db. OrderDetail. All (). Where (db. OrderDetail. Price = 400.to( 440); //

Var products = db. product. All (). Where (db. Product. FactoryName. Like ("% a %"); // like


Which of the following books is better than "Linux Standard learning tutorial" and "Basic Linux Private food for laruence?

I personally strongly recommend "laruence's Linux private house dish".
The content is easy to understand and suitable for beginners. It is humorous and well-organized.
Compared with textbooks in China, it is much better.

How to learn the basics of super cartoon sketch Techniques

From the very beginning, I believe you will succeed in more hands-on exercises and copies!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.