Advanced for simple. data, advanced for simple. data

Source: Internet
Author: User

Advanced for simple. data, advanced for simple. data

I. sorting results

-OrderBy (ascending)

-OrderByDescending (in descending order)

db.Product.All().OrderByFactoryName();db.Product.All().OrderByFactoryNameDescending();

Or

db.Product.All().OrderBy(db.Product.FactoryName);db.Product.All().OrderByDescending(db.Product.FactoryName);

Ii. Table join

1. No foreign key constraints

1.1 natural connections

-Join

-Left Join

-Outer Join

var q = _db.Order.Query().Join(_db.OrderDetail, ).Where(_db.OrderDetail.UnitPrice > 15000);List<dynamic> employees = q.Select(_db.Order.OrderCode, q.OrderDetail.CategoryName).ToList();

1.2 cascading Query

-

-WithOne

-WithMany

dynamic OrderDetailAlias;var OrderDetails = db.Order.All().With(db.Order.OrderDetail.As("OrderDetailInfo"), out OrderDetailAlias) 
.Select( db.Order.OrderCode, BandAlias.Name);

 

 

2. Foreign key constraints

2.1. A single dataset is returned

var orders = _db.Order.FindAllByCustomerId(10).Select(_db.Order.OrderCode, q.Order.OrderDetail.CategoryName);

(Using the foreign key of the database)

 

var orders = _db.Order.FindAllByCustomerId(10).Select(_db.Order.OrderCode, _db.OrderDetail.CategoryName).Join(_db.OrderDetail).On(OrderId: _db.Order.PKID);

(Replace foreign key)

var orders = _db.Order.FindAllByCustomerId(10).Select(_db["Order"]["OrderCode"], _db["OrderDetail"]["CategoryName"]).Join(_db["OrderDetail"]).On(OrderId: _db["Order"]["PKID"]);

(Replace foreign key-index writing)

Iii. Aggregate functions

1. Having

var orderDetails= db.OrderDetail.All().Select(db.OrderDetail.Order.OrderCode,         db.OrderDetail.PKID.Count().As("OrderDetailCount")).Having(db.OrderDetail.PKID.Count() > 2);

 

2. Max, Min, Sum, Count, and Avg

var orderDetails=db.OrderDetail.All().Having(db.OrderDetail.UnitPrice.Max()>100);
var orderDetails=db.OrderDetail.All().Having(db.OrderDetail.UnitPrice.Min()>100);

3. Count, CountDistinct

Var orderDetails = db. orderDetail. all (). select (db. orderDetail. orderId. count (); var orderDetails = db. orderDetail. all (). select (db. orderDetail. orderId. countDistinct (); deduplication count

 

Iv. Help Functions

1. Length (field Length)

var codeLength=db.Order.Select(db.Order.OrderCode.Length().As("CodeLength"));

2. Convert to Scalar Value

2.1. ToScalar and ToScalar <T> return an attribute as the scalar value from the query results.

int id=db.Order.Get(1).ToScalar();int id=db.Order.Select(db.Order.Id).Get(1).ToScalar();

 

2.2. ToScalarOrDefault and ToScalarOrDefault <T> return an attribute from the query result as the scalar value, which is the default value. If the attribute value is NULL, ToScalarOrDefault <T> Returns default <T>

string orderCode=db.Order.FindAllById(1).Select(db.Order.OrderCode).ToScalarOrDefault();

 

2.3. ToScalarList and ToScalarList <T> return a list from a series of query results as scalar values.

List<string> orderDetails=db.OrderDetail.FindAllByOrderId(1).Select(db.OrderDetail.CategoryName).ToScalarList<string>();

 

2.4. ToScalarArray and ToScalarArray <T> return an array as the scalar value from a series of query results.

string[] orderDetails=db.OrderDetail.FindAllByOrderId(1).Select(db.OrderDetail.CategoryName).ToScalarArray<string>();

 

To be continued...


AutoCAD 2010 full learning manual-mechanical entry-advanced-proficient

If you are just a beginner, you don't have to stick to the same version. The basics are the same. There are a lot of books on the Internet and I don't have them on my hard disk! We recommend that you use Baidu!

How to get started with DSP

Let me try it.

Youku

Cool 6

Sina video

There are a lot

It should be free of charge
 

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.