// 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