À la maison » Filet de point

Cours d'instruction de LINQ avec le cadre 3.0 et 3.5 de filet de point

Avec l'avancement des technologies et de la base de données c'est devenu un grand défi pour rechercher des données plus rapidement et avec moins de fardeau sur la pièce de programmation.

Il est devenu évident que le prochain grand défi en technologie de programmation est de réduire la complexité d'information de accès et de intégration qui n'est pas définie à la façon des indigènes en utilisant la technologie d'OO. Les deux sources les plus communes d'information de non-OO sont les bases de données relationnelles et les XML.

L'avantage principal de Microsoft ? projet de s LINQ est l'approche générale qu'ils ont adoptée parce qu'ils ont intégré un langage d'interrogation indépendamment de n'importe quelle partie spécifique. La question intégrée par langue peut être employée avec XML, base de données ou quelque chose qui sont capables de renvoyer IENUMERABLE.

Voici un petit cours d'instruction qui peut expliquant. C'est particulièrement pour mes lecteurs qui aiment faire à porgamming.

C'est un extrait que j'ai trouvé dans le Doc. lui-même qui peut exprimer la puissance de LINQ et faire des programmeurs du filet de point vraiment sourire.

employer le système ; employer System.Query ;
employer System.Collections.Generic ;
classe APP {
force vide de charge statique () {
ficelez [] appelle = {? Étouffez ? ? Connor ? ? Frank ? ? Everett ? ? Albert ? ? George ? ? Harris ? ? David ? };

Expr d'IEnumerable = de s dans les noms
là où (== 5 s orderby de s.Length)
choisissez s.ToUpper () ;
foreach (article de corde dans l'expr)
Console.WriteLine (article) ;

}

}

Comment Linq fonctionne-t-il avec XML ?

L'extensibilité de l'architecture de question est employée dans le projet de LINQ lui-même pour fournir les réalisations qui fonctionnent au-dessus des données de XML et de SQL.

Xpath et Xquery qui est employé fortement est dans le langage de programmation de centre serveur. Voici encore un extrait de code pour montrer à quel point il facile est de travailler avec LINQX (oui qui est ce qui son réclamé XML ? s)

La manière standard est faite comme suit :

XmlDocument Doc. = nouveau XmlDocument () ;
Nom de XmlElement = doc.CreateElement ( » nom ») ;
name.InnerText = « Patrick Hines » ;
XmlElement phone1 = doc.CreateElement ( » téléphone ») ;
phone1.SetAttribute ( » type », « à la maison ») ;
XmlElement phone2 = doc.CreateElement ( » téléphone ») ;
phone2.SetAttribute ( » type », « travail ») ;
XmlElement street1 = doc.CreateElement ( » ″ street1) ;
Ville de XmlElement = doc.CreateElement ( » ville ») ;
city.InnerText = « île de Mercer » ;
État de XmlElement = doc.CreateElement ( » état ») ;
state.InnerText = « WA » ;
XmlElement postal = doc.CreateElement ( » postal ») ;
postal.InnerText = « ″ 68042 ;
Adresse de XmlElement = doc.CreateElement ( » adresse ») ;
address.AppendChild (street1) ;
address.AppendChild (ville) ;
address.AppendChild (état) ;
address.AppendChild (postal) ;
Contact de XmlElement = doc.CreateElement ( » contact ») ;
contact.AppendChild (nom) ;
contact.AppendChild (phone1) ;
contact.AppendChild (phone2) ;
contact.AppendChild (adresse) ;
XmlElement entre en contact = doc.CreateElement ( » contacts ») ;
contacts.AppendChild (contact) ;
doc.AppendChild (contacts) ;

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: , ,

Translate to EnglishÜbersetzen Sie zum Deutsch/GermanΜεταφράστε στα ελληνικά/GreekПереведите к русскому/RussianOversetter til Norsk/NorwegianÖversätta till Svensk/Swedishहिनà¥à¤¦à¥€ अनà¥à¤µà¤¾à¤¦ करने के लिà¤/Hindi
Tradueix al català/CatalanTulkot uz latviešu/LatvianPreložiť do slovenčiny/SlovakVertaal aan het Nederlands/Dutchترجمة الى العربية/ArabicTraduzca al Español/SpanishTraduisez au Français/French
Traduca ad Italiano/ItalianTraduza ao Português/Portuguese日本語に翻訳しなさい /Japanese한국어에게 번역하십시오/Korean中文翻译/Chinese Simplified中文翻译/Chinese TraditionalПереклад на українську/Ukrainian
We Recommend : Click here to run a Free Performance scan
SMS subscribe Print This Post

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



6 Comments »

  • Oliver said:

    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.

  • Ashish Mohta (author) said:

    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 )

  • Stjepan said:

    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…

  • Ashish Mohta (author) said:

    @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

  • Tiiso :D said:

    Hello, Ashish, thanks for the post. As for Stjepan lol he still spelt Hassles wrong. So sad. Enjoy. Keep up the good work :D

  • Ashish Mohta (author) said:

    Thanks Tisso!!

Leave your response!

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>