IT Boxing Championship

Download Report

Transcript IT Boxing Championship

LINQ Providers

Or why .NET rules, and Java doesn’t Branimir Giurov SofiaDev.org UG Lead, C# MVP Freelance Software Developer www.sofiadev.org

Contents

• •

typeof(linq) How does it work?

Lambda, extension methods, iterators

typeof(linq)

C# 3.0

VB 9.0

Others… .NET Language Integrated Query LINQ to Objects LINQ to Datasets LINQ to SQL LINQ to Entities LINQ to XML Objects Relational <author/> <year/> <price/> </book> XML</b></p> <a id="p5" href="#"></a> <h3><b>typeof(linq)</b></h3> <p>• • • • • • • • •</p> <p><b>LINQ to Objects LINQ to SQL LINQ to XML LINQ to Datasets LINQ to Entities LINQ to Windows Search LINQ to Google LINQ to Sharepoint LINQ to nHibernate</b></p> <a id="p6" href="#"></a> <h3><b>LINQ to Objects</b></h3> <p>•</p> <p><b>Query language over collections of objects</b></p> <p>•</p> <p><b>Standard SQL-like set of query operators, including joins and grouping</b></p> <p>•</p> <p><b>New query operators can be added, fully extensible (extension methods)</b></p> <p>•</p> <p><b>Intellisense and compiler syntax checking support in Visual Studio</b></p> <a id="p7" href="#"></a> <h3><b>LINQ to Objects</b></h3> <p>•</p> <p><b>How to query an array of int?</b></p> <p><b>public void Linq1() { int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 }; var lowNums = from n in numbers where n < 5 select n; Console.WriteLine("Numbers < 5:"); foreach (var x in lowNums) { Console.WriteLine(x); } }</b></p> <a id="p8" href="#"></a> <h3><b>LINQ to SQL</b></h3> <p>• • • • • •</p> <p><b>Write queries in any .NET language to retrieve and manipulate data from SQL Use FK constraints for defining relations of data without joins Join in code on any column that has no FK defined Use FK’s to query/modify data in SQL DB Call SubmitChanges() when you’re done Currently supports SQL 2000 & 2005</b></p> <p>•</p> <p><b>System.Date.Linq.SqlClient.Sql2000Provider</b></p> <p>•</p> <p><b>System.Date.Linq.SqlClient.Sql2005Provider</b></p> <a id="p9" href="#"></a> <p><b>DEMO LINQ to SQL ToString() Modifying Queries Mapping Styles Mapping Tools</b></p> <a id="p10" href="#"></a> <h3><b>LINQ to XML</b></h3> <p>• •</p> <p><b>LINQ to XML is a new way to construct, write and read XML data in the .NET language of the developers’ choice Simplifies working with XML </b></p> <p>• • • • •</p> <p><b>No more XPath or XSLT Not a replacement for DOM or any of the current XML libs Supports writing Query Expressions Can be combined with any of the other LINQ technologies Supports SAX-style reading/writing of documents with the use of XStreamingElement</b></p> <p>•</p> <p><b>Differed execution</b></p> <a id="p11" href="#"></a> <h3><b>LINQ to XML</b></h3> <p>•</p> <p><b>Combining it with other LINQ technologies makes life easier XElement xml = new new new new XElement("contacts", XElement("contact", new XAttribute("contactId", "2"), new new XElement("firstName", "Barry"), XElement("lastName", "Gottshall") ), XElement("contact", new XAttribute("contactId", "3"), new XElement("firstName", "Armando"), XElement("lastName", "Valdes") ) );</b></p> <a id="p12" href="#"></a> <h3><b>LINQ to XML</b></h3> <p>•</p> <p><b>Result from previous example: <contacts> <contact contactId="2"> <firstName>Barry</firstName> <lastName>Gottshall</lastName> </contact> <contact contactId="3"> <firstName>Armando</firstName> <lastName>Valdes</lastName> </contact> </contacts></b></p> <a id="p13" href="#"></a> <h3><b>LINQ to DataSet(s)</b></h3> <p>• • • • •</p> <p><b>Allows developers to query existing DataSet sources within applications Offline, still uses IQueryable<T> approach 2 types of queries, depending on use of typed/un typed datasets Use LINQ in current applications without re-writing using LINQ to SQL Bi-directional: LINQ Sequence -> DataTable -> LINQ Sequence support</b></p> <a id="p14" href="#"></a> <h3><b>How Does it Work?</b></h3> <p>•</p> <p><b>Depends on if the type is {0} or not</b></p> <p>•</p> <p><b>IQueryable<T></b></p> <p>• •</p> <p><b>System.Linq.Queryable (System.Data.Linq.DataQuery<T>)</b></p> <p>•</p> <p><b>SQL</b></p> <p>•</p> <p><b>Entity</b></p> <p>•</p> <p><b>Datasets The extension methods build an expression tree</b></p> <p>•</p> <p><b>If not, then check if it is a IEnumerable<T></b></p> <p>•</p> <p><b>System.Linq.IEnumerable<T></b></p> <p>•</p> <p><b>Objects</b></p> <p>•</p> <p><b>XML</b></p> <p>•</p> <p><b>The extension methods run the query</b></p> <a id="p15" href="#"></a> <h3><b>How Does it Work?</b></h3> <p><b>C# 3.0</b></p> <p><b>VB 9.0</b></p> <p><b>Others… .NET Language Integrated Query LINQ to Objects LINQ to Datasets LINQ to SQL LINQ to Entities LINQ to XML Objects Relational <book> <title/> <author/> <year/> <price/> </book> XML</b></p> <a id="p16" href="#"></a> <h3><b>How Does it Work?</b></h3> <p>• • • •</p> <p><b>Extension methods for the from/select/where/groupby keywords Lambda expressions Expression tree for building & pre-compiling the statement that will run on a IQueryable<T></b></p> <p>•</p> <p><b>p=> p.CompanyName.StartsWith</b></p> <p><b>(“A”) Iterators for the in-memory queries (IEnumerable<T>)</b></p> <p>•</p> <p><b>foreach on an IEnumerable<T></b></p> <a id="p17" href="#"></a> <h3><b>What’s Next?</b></h3> <p>•</p> <p><b>PLINQ</b></p> <p>•</p> <p><b>Parallel FX Library</b></p> <p>•</p> <p><b>IParallelEnumerable<T></b></p> <p>•</p> <p><b>CTP is available</b></p> <p>•</p> <p><b>Support for 3 rd party DB engines</b></p> </div> </section> </div> </div> </div> </main> <footer> <div class="container mt-3"> <div class="row justify-content-between"> <div class="col"> <a href="/"> <img src="/theme/studyslide/static/logo-slideum.png" /> </a> </div> </div> <div class="row mt-3"> <ul class="col-sm-6 list-unstyled"> <li> <h6 class="mb-3">Company</h6> <li> <i class="fa fa-location-arrow"></i> Nicosia Constantinou Palaiologou 16, Palouriotissa, 1040 <li> <i class="fa fa-phone"></i> +357 64-733-402 <li> <i class="fa fa-envelope"></i> info@slideum.com </ul> <ul class="col-6 col-sm-3 list-unstyled"> <li> <h6 class="mb-3">Links</h6> <li> <a href="/about">About</a> <li> <a href="/contacts">Contact</a> <li> <a href="/faq">Help / FAQ</a> </ul> <ul class="col-6 col-sm-3 list-unstyled"> <li> <h6 class="mb-3">Legal</h6> <li> <a href="/terms">Terms of Service</a> <li> <a href="/privacy">Privacy policy</a> <li> <a href="/page.html?code=public.usefull.cookie">Cookie policy</a> <li> <a href="/page.html?code=public.usefull.disclaimer">Disclaimer</a> </ul> </div> <hr> <p>slideum.com © 2024, Inc. All rights reserved.</p> </div> </footer> <div class="modal directory" id="directory-modal"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title">Directory</h5> <button class="close" type="button" data-dismiss="modal">×</button> </div> <div class="modal-body"></div> </div> </div> </div> <script src="/theme/common/static/jquery@3.5.1/dist/jquery.min.js"></script> <script src="/theme/common/static/jquery_extra/dist/jquery-extra.js"></script> <script src="/theme/common/static/popper.js@1.16.1/dist/umd/popper.min.js"></script> <script src="/theme/common/static/bootstrap@4.6.0/dist/js/bootstrap.min.js"></script> <script> var __path_directory = [ ] !function __draw_directory(data, root, uuid) { var ul = $('<ul>', uuid && { id: 'category' + uuid, class: !__path_directory.includes(uuid) ? 'collapse' : null }); for (var item in data) { var li = $('<li>').appendTo(ul); if (item = data[item], item.children) { li.append('<a href=#category' + item.id + ' data-toggle=collapse>') __draw_directory(item.children, li, item.id); } else { li.append('<a href=' + item.url + '>'); } var a = $('> a', li).addClass('item').text(item.name) .append($('<a class="link fa fa-external-link" href=' + item.url + '>')); if (item.id === +__path_directory.slice(-1)) { a.addClass('active'); } /* if (item.id !== __path_directory[0]) { a.addClass('collapsed'); } */ } root.append(ul); } ([{"id":1,"name":"Food and cooking","url":"/catalog/Food+and+cooking","children":null},{"id":2,"name":"Education","url":"/catalog/Education","children":null},{"id":3,"name":"Healthcare","url":"/catalog/Healthcare","children":null},{"id":4,"name":"Real estate","url":"/catalog/Real+estate","children":null},{"id":5,"name":"Religion ","url":"/catalog/Religion+","children":null},{"id":6,"name":"Science and nature","url":"/catalog/Science+and+nature","children":null},{"id":7,"name":"Internet","url":"/catalog/Internet","children":null},{"id":8,"name":"Sport","url":"/catalog/Sport","children":null},{"id":9,"name":"Technical documentation","url":"/catalog/Technical+documentation","children":null},{"id":10,"name":"Travel","url":"/catalog/Travel","children":null},{"id":11,"name":"Art and Design","url":"/catalog/Art+and+Design","children":null},{"id":12,"name":"Automotive","url":"/catalog/Automotive","children":null},{"id":13,"name":"Business","url":"/catalog/Business","children":null},{"id":14,"name":"Government","url":"/catalog/Government","children":null}], $('#directory-aside')); var __root_directory = $('#directory-aside > ul'); $('#directory-aside') .on('show.bs.collapse', function() { //console.log('show.collapse') }) .on('hide.bs.collapse', function() { //console.log('hide.collapse') }); $('#directory-modal') .on('show.bs.modal', function() { $('[class$="body"]', this).prepend(__root_directory); }) .on('hide.bs.modal', function() { $('#directory-aside').prepend(__root_directory); }); $('.directory-mobile').on('click', function(e) { e.preventDefault(); }); $('.directory .link').on('click', function(e) { e.stopPropagation(); }); </script> <script> function scrollToViewport() { $('html, body').stop().animate( { scrollTop: $('.navbar').outerHeight() }, 1000); } setTimeout(scrollToViewport, 1000); $(window).on('orientationchange', scrollToViewport); $('[data-toggle="tooltip"]').tooltip(); </script> <script async src="//s7.addthis.com/js/300/addthis_widget.js#pubid=#sp('addthis_pub_id')"></script> <!-- Yandex.Metrika counter --> <script type="text/javascript"> (function (d, w, c) { (w[c] = w[c] || []).push(function() { try { w.yaCounter28397281 = new Ya.Metrika({ id:28397281 }); } catch(e) { } }); var n = d.getElementsByTagName("script")[0], s = d.createElement("script"), f = function () { n.parentNode.insertBefore(s, n); }; s.type = "text/javascript"; s.async = true; s.src = (d.location.protocol == "https:" ? "https:" : "http:") + "//mc.yandex.ru/metrika/watch.js"; if (w.opera == "[object Opera]") { d.addEventListener("DOMContentLoaded", f, false); } else { f(); } })(document, window, "yandex_metrika_callbacks"); </script> <noscript><div><img src="//mc.yandex.ru/watch/28397281" style="position:absolute; left:-9999px;" alt="" /></div></noscript> <!-- /Yandex.Metrika counter --> <link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.1.0/cookieconsent.min.css" /> <style> @media screen and (max-width: 768px) { .cc-revoke { display: none; }} </style> <script src="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.1.0/cookieconsent.min.js"></script> <script> window.addEventListener("load", function() { window.cookieconsent.initialise( { content: { href: "https://slideum.com/dmca" }, location: true, palette: { button: { background: "#fff", text: "#237afc" }, popup: { background: "#007bff" }, }, position: "bottom-right", revokable: true, theme: "classic", type: "opt-in" })}); </script> </body> </html>