Add, query, modify, and delete

Source: Internet
Author: User

// Obtain the connection
Private opalsoftubdatadatacontext DB = new opalsoftubdatadatacontext ("Data Source = 192.168.1.104; initial catalog = opalsoft. UB; user id = sa; Password = 123 ");
# Type of products added by region
/// <Summary>
/// Type of the added product
/// </Summary>
/// <Param name = "category"> product type object </param>
Public void addcategory (Category category)
{
DB. Category. insertonsubmit (category );
DB. submitchanges ();
}
# Endregion

# Add region users to favorites and follow the product type
/// <Summary>
/// Add a user to favorites and follow the product type
/// </Summary>
/// <Param name = "bookmark"> Add product type objects to favorites </param>
Public void addusercategory (bookmark)
{
DB. bookmark. insertonsubmit (bookmark );
DB. submitchanges ();
}
# Endregion

# Region user deletes a favorite product type
/// <Summary>
/// Delete the favorite product type
/// </Summary>
/// <Param name = "bookmark"> bookmark object </param>
Public void deleteusercategory (bookmark)
{
Bookmark newbookmark = dB. bookmark. Single (P => P. bm_id = bookmark. bm_id );
Newbookmark. Status = "X ";
DB. submitchanges ();
}
# Endregion

# Region query whether a user has added a record
/// <Summary>
/// Query whether a user has added a record
/// </Summary>
/// <Param name = "userid"> User ID </param>
/// <Param name = "bm_link_id"> Add a follow ID to favorites </param>
/// <Param name = "type"> type </param>
/// <Returns> whether bool has this record </returns>
Public bool usercategorycount (INT userid, int bm_link_id, string type)
{
Bool temp = true;
Int annal = dB. bookmark. Count (P => P. user_id = userid & P. bm_link_id = bm_link_id & P. bm_link_type = type );
If (annal! = 0)
{
Temp = false;
}
Return temp;
}
# Endregion

# Region add-to-favorites product changed to
/// <Summary>
/// The status of the added product changes to.
/// </Summary>
/// <Param name = "bookmark"> bookmark object </param>
Public void updateusercategory (bookmark)
{
Bookmark newbookmark = dB. bookmark. Single (P => P. bm_id = bookmark. bm_id );
Newbookmark. Status = "";
DB. submitchanges ();
}
# Endregion

# Region
/// <Summary>
/// Retrieve the user's favorite
/// </Summary>
/// <Param name = "userid"> User ID </param>
/// <Param name = "type"> type </param>
/// <Returns> list set </returns>
Public list <bookmark> getuserusercategory (INT userid, string type)
{
List <bookmark> List = dB. bookmark. where (P => P. user_id = userid & P. bm_link_type = type & P. status = ""). tolist <bookmark> ();
Return list;
}
# Endregion

# Region obtain the product type of the previous level
/// <Summary>
/// Obtain the product type of the previous level
/// </Summary>
/// <Param name = "upcid"> Level 1 ID. 0 indicates level 1 ID. </param>
/// <Returns> list set </returns>
Public list <Category> getcategory (INT upcid)
{
List <Category> List = dB. Category. Where (P => P. parent_cate_id = upcid & P. Status = "A"). tolist <Category> ();
Return list;
}
# Endregion

// Write a delete statement below. Because all operations are performed to modify the state, write another method! -_-
Public void deletesample ()
{
DB. Category. deleteonsubmit (db. Category. Single (C => C. cate_id = 4 ));
}

Category: LINQ

Add, query, modify, and delete

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.