Nhibto to linq

Source: Internet
Author: User

Problems encountered during the use of nhib.pdf and some fragmented knowledge after constant solution:

1. Express:

After Express declares a variable, it can save a lamda expression, Express exp = (o => o. fieldname), which can dynamically combine the fields to be queried.

Code:

Expression <Func <Gx. Model. Author, bool> where1, where2;
If (CityId! = 0)
{
// StrCity = "and other_City =" + CityId;
Where1 = o => o. OtherCity = CityId;
}
Else where1 = o => o. AuthorId! = Null;
If (Types)
{
// StrPhoto = "and Photo1 is not null ";
Where2 = o => o. Photo1! = Null;

}
Else where2 = o => o. AuthorId! = Null;
Var list1 = new Author (). CreateQueryOver (). Where (where1)

. Where (where2)
. OrderBy (o => o. AuthorId). Desc

. Take (NO)
. List <Gx. Model. Author> (); // obtain the latest member.

 

 

 

 

Ii. Sorting after table connection.

IList <Gx. Model. MessageBoard> MessBoard = (from m in iq2
// From t in m. MessageBoards
//. OrderByDescending (o => o. MessageBoards. Select (oo => oo. MBMessageDate ))
// From t in m. Orders
Join m2 in iq
On m. AuthorId equals m2.Author. AuthorId into m3

From t in m3
Orderby t. AuthorID
Select new Gx. Model. MessageBoard {Mb_id = t. Mb_id, FromID = t. FromID, Realname = t. FromID! = 0? T. Author. RealName: t. Realname, MBIP = t. FromID! = 0? T. Author. OtherAddress: t. MBIP, MBMessage = t. MBMessage, MBMessageDate = t. MBMessageDate, Author = t. Author })
//. Orderby (o => o. AuthorID)
. Take (Count)
. ToList <Gx. Model. MessageBoard> ();

An error (Invalid Path) will be reported when sorting is like the red font above ).

Solution:

MessBoard = MessBoard .. Orderby (o => o. AuthorID). ToList ();

 

 

 

 

3. nhib.pdf provides the same functions as case when:

Condition: An IQueryable and linq query must be returned during data access (convenient ).

Select new Gx. Model. MessageBoard {Mb_id = t. Mb_id, FromID = t. FromID, Realname = t. FromID! = 0? T. Author. RealName: t. Realname, MBIP = t. FromID! = 0? T. Author. OtherAddress: t. MBIP, MBMessage = t. MBMessage, MBMessageDate = t. MBMessageDate, Author = t. Author })

The above is just a few scattered essays. If there are any mistakes, criticize and correct them.

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.