Σεμινάριο LINQ στο πλαίσιο 3.0 και 3.5 δικτύου σημείων
Με την πρόοδο των τεχνολογιών και της βάσης δεδομένων έχει γίνει μια μεγάλη πρόκληση για να ανακτήσει τα στοιχεία γρηγορότερα και με το λιγότερο φορτίο στον προγραμματισμό του μέρους.
Έχει γίνει προφανές ότι η επόμενη μεγάλη πρόκληση στον προγραμματισμό της τεχνολογίας είναι να μειωθεί η πολυπλοκότητα της πρόσβασης και της ενσωμάτωσης των πληροφοριών που δεν καθορίζονται natively χρησιμοποιώντας την τεχνολογία OO. Οι δύο πιό κοινές πηγές πληροφοριών μη-OO είναι σχεσιακά βάσεις δεδομένων και XML.
Το σημαντικότερο πλεονέκτημα Microsoft; πρόγραμμα του s LINQ είναι η γενική μέθοδος που έχουν υιοθετήσει επειδή έχουν ενσωματώσει μια γλώσσα διατύπωσης ερωτήσεων ανεξάρτητα από οποιοδήποτε συγκεκριμένο μέρος. Ενσωματωμένη η γλώσσα ερώτηση μπορεί να χρησιμοποιηθεί με XML, τη βάση δεδομένων ή τίποτα που είναι σε θέση της επιστροφής IENUMERABLE.
Εδώ είναι ένα μικρό σεμινάριο που μπορεί εξηγώντας. Αυτό είναι ειδικά για τους αναγνώστες μου που αγαπούν να κάνουν.
Αυτό είναι ένα απόκομα που βρήκα το ίδιο στο έγγραφο που μπορεί να εκφράσει τη δύναμη LINQ και να κάνει τους προγραμματιστές του σημείου το καθαρό πραγματικά χαμόγελο.
χρησιμοποίηση του συστήματος χρησιμοποίηση System.Query
χρησιμοποίηση System.Collections.Generic
κατηγορία app {
στατικός κενός κεντρικός αγωγός () {
η σειρά [] ονομάζει = {; Burke; ; Connor; ; Frank; ; Everett; ; Αλβέρτος; ; George; ; Harris; ; Δαβίδ; };IEnumerable expr = από το s στα ονόματα
όπου (s.Length == 5 το orderby s)
επιλέξτε s.ToUpper ()
foreach (στοιχείο σειράς στο expr)
Console.WriteLine (στοιχείο)}
}
Πώς εργασίες Linq με XML;
Το εκτατό της αρχιτεκτονικής ερώτησης χρησιμοποιείται το ίδιο στο LINQ πρόγραμμα για να παρέχει τις εφαρμογές που λειτουργούν και πέρα από XML και πέρα από τα στοιχεία SQL.
Το Xpath και Xquery που χρησιμοποιείται ευρέως είναι στη γλώσσα προγραμματισμού οικοδεσποτών. Εδώ είναι πάλι ένα απόκομα κώδικα για την επίδειξη πόσο εύκολο είναι να εργαστεί με LINQX (ναι που είναι τι απαιτημένο XML του; του s)
Ο τυποποιημένος τρόπος γίνεται ως εξής:
XmlDocument έγγραφο = νέο XmlDocument ()
Όνομα XmlElement = doc.CreateElement (» όνομα»)
name.InnerText = «Πάτρικ Hines»
XmlElement phone1 = doc.CreateElement (» τηλέφωνο»)
phone1.SetAttribute (» τύπος», «σπίτι»)
XmlElement phone2 = doc.CreateElement (» τηλέφωνο»)
phone2.SetAttribute (» τύπος», «εργασία»)
XmlElement street1 = doc.CreateElement (» street1 ″)
Πόλη XmlElement = doc.CreateElement (» πόλη»)
city.InnerText = «νησί υφασματεμπόρων»
Κράτος XmlElement = doc.CreateElement (» κράτος»)
state.InnerText = «WA»
XmlElement ταχυδρομικό = doc.CreateElement (» ταχυδρομικός»)
postal.InnerText = «68042 ″
Διεύθυνση XmlElement = doc.CreateElement (» διεύθυνση»)
address.AppendChild (street1)
address.AppendChild (πόλη)
address.AppendChild (κράτος)
address.AppendChild (ταχυδρομικός)
Επαφή XmlElement = doc.CreateElement (» επαφή»)
contact.AppendChild (όνομα)
contact.AppendChild (phone1)
contact.AppendChild (phone2)
contact.AppendChild (διεύθυνση)
Το XmlElement έρχεται σε επαφή με = doc.CreateElement (» επαφές»)
contacts.AppendChild (επαφή)
doc.AppendChild (επαφές)
If we see it little closer the above code , This style of coding provides few clues to the structure of the XML tree. but with LINQX it becomes more of what they as functional construct.Here is what how u code the same with LINQX?.
XElement contacts = new XElement
(”contacts”,new XElement(”contact”,
new XElement(”name”, “Patrick Hines”),
new XElement(”phone”, “206-555-0144″,
new XAttribute(”type”, “home”))
,new XElement(”phone”, “425-555-0145″,new XAttribute(”type”, “work”)),
new XElement(”address”,new XElement(”street1″, “123 Main t”),
new XElement(”city”, “Mercer Island”),
new XElement(”state”, “WA”),new XElement(”postal”,”6843″)
This is so simple no hassles at all.
How LINQ works with database
Yup its done By Microsoft again under LINQD(thats LINQ for database). The query operators over relational data (DLinq) build on the integration of SQL-based schema definitions into the CLR type system.
This integration provides strong typing over relational data while retaining the expressive power of the relational model and the performance of query evaluation directly in the underlying store.
What we kneed to know is the structure of database table we want to deal with it and create a class exactly having private variables as columns of the underlying table say may be like save that easy.Thus in simple way we create an object of the row of that table in memory and do operation on that and ask somebody to save it.Moreover we can ask for a collection of those rows fo get more than one record and do a query on it..isnt that great no hassles of database sql.
1. Create an entity class with mapping to database table like this:-
[Table(Name="Customers")]
public class Customer
{
[Column (Id=true)]
public string CustomerID;
private string _City;
[Column(Storage = "_City")]
public string City
{
get { return this._City; }
set { this._City = value; }}}
2.Create a Data context to load from database
static void Main(string[] args){
// Use a standard connection string
DataContext db = new DataContext(
@?C:Program FilesLINQ PreviewDatanorthwnd.mdf?);
// Get a typed table to run queries
Table Customers = db.GetTable();
3.Query what you get?.
// Attach the log showing generated SQL to console
// This is only for debugging / understanding the working of DLinq
db.Log = Console.Out;
// Query for customers in London
var custs =
from c in Customers
where c.City == “London”
select c;
}
Thats how it works with database?.easy isn’t it?This Technology will come with DotNet Framework 3.0 and with C#3.0 and VB 9. I havent covered every thing but just a quick glance which can get grasping things faster. If you want to read more on it see the Microsoft?s LINQ Project
Related : Linq provider for Twitter API
Tags: dot-net-framework3, Microsoft, msdn
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
Posted on 21st May 2007 by Ashish Mohta , A tech blogger who writes about solving day to day problems of people who use computer. He also writes on How to use the applications like Office, PC tips, Online tools,Browsers and more. All posts by Ashish Mohta | Connect with me @
Twitter |
Linkedin |
Facebook |
Stumble
| Need more help? Ask your Questions at our Support Center


































I don’t understand….you write on how to use tools in office, when one of the most basic (spellchecker) obviously went unused in this report. Thumbs way down to you Hashish. Way down.
Hi Oliver, Why dont you enlighten all of us reading this with your devine knowledge on this subject ?
Regards
ASHISH ( without start H in Hashish )
heavily — heavily
explaing — explain
lil ??? — little
fo — to
hassels — hassels
isint — isn’t
Frameowrk - Framework
Here is a free tip for you — Tools > Spelling and Grammar…
@Stjepan and Oliver : Thanks for pointing it out. I guess I still get scolded for my older posts but thanks. I had made the corrections
Hello, Ashish, thanks for the post. As for Stjepan lol he still spelt Hassles wrong. So sad. Enjoy. Keep up the good work
Thanks Tisso!!
Leave your response!
Subscribe for Daily Updates
Free Feed Subscription
Weekly Podcast
Monthly Archives
Topics
What others are Saying ?