In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains the "linq to sql multi-table query how to achieve", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in-depth, together to study and learn "linq to sql multi-table query how to achieve" it!
In the era of handwritten sql, if you want to fetch a few pieces of data randomly from sqlserver database, you can easily use order by NewId (), and you can also use select * from AMagi B Where A.ID=B.ID to realize linq to sql multi-table query, but how to realize these functions in linq to sql?
Key points of linq to sql multi-table query:
1. Random ordering problem: you can use Select (d = > new {NewId=new Guid ()}) .OrderBy (d = > d.NewId) to achieve the effect of order by NewId ().
2.linq to sql multi-table query
From an in TableA from b in TableB where a.ID = = b.ID
In addition, using linq to xml, you can easily save the query results as xml (which is indeed much more novel than the traditional xml method).
For detailed code, please refer to my example in a project (the function is to randomly pick up the records of 10 product videos and generate a xml for the player to call)
Using (DBDataContext db = new DBDataContext (Database.ConnectionString)) {var Q = db.T_Shops.Where (s = > s.F_ID = = new Guid ("00000000-0000-0000-0000-0000000001") .Select (s = > new... {s.F_AutoID}) .First (); string _ ShopAutoId = q.F_AutoID.ToString () Var query = (from v in db.V_ProductVideos from pv in db.V_ProductTV where v.F_ShopID = = new Guid ("00000000-0000-0000-0000-0000000001") & & v.F_ProductID = = pv.F_ID & & pv.F_Status = = 1 & & pv.F_isShow = = 1 & & v.F_Status = = 1 & & v.F_ProductStatus = = 1 Select new... {v.F_VideoS V.F_VideoP, v.F_VideoW, v.F_VideoL, v.F_ClsAutoID, v.F_ProductName, v.F_ProductAutoID, NewId = Utils.NewComb ()} .OrderBy (p = > p.NewId) .Take (10) / use linq to xml to generate xml XDocument doc = new XDocument (new XElement ("flvLists", from d in query select (new XElement ("item", new XAttribute ("title_p", d.F_VideoP), new XAttribute ("title_s", d.F_VideoS), new XAttribute ("name", Utils.NoHtml (d.F_ProductName, 500)), new XAttribute ("link") + d.F_ClsAutoID.ToString () + "/" + _ ShopAutoId + "/" + d.F_ProductAutoID) Doc.Save (Server.MapPath ("~ / upload/xml/tvvideo.xml")); db.Connection.Close ();} Thank you for your reading, the above is the content of "how to implement linq to sql multi-table query". After the study of this article, I believe you have a deeper understanding of how to achieve linq to sql multi-table query, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.