Freigeben über


Linq ROCKS!

So I have finally started to look at Linq and what it can do.  Wow am I amazed.  The language is very close to SQL so it was easy to pick up.  Fortunately the language goes beyond what you can do in SQL so I've got quite a bit more stuff to learn about it.  So far I've used it to connect to the database via SqlMetal.exe and to object collections. 

 var sortedFiles = 
    from fi in _db.Files
    join fileXplat in _db.FilePlatformXrefs on fi.Id equals fileXplat.FileId
    join plat in _db.Platforms on fileXplat.PlatformId equals plat.Id
    where fi.ComponentId == ComponentParentId
    select new
    {
        SourceFileName = fi.SourceFileName,
        Guid = fi.Component.ComponentGUID,
        Source = String.Concat(fi.Source.Path, fi.SourcePath),
        Platform = plat.Name,
        Key = fi.IsKeyFile,
        Id = fi.Id,
        Compressed = fi.UnCab
    };

This query is a bit complex with a few joins and only pulling out a few columns.  I even have a string concatenation inside the query to pre format the data.  I'm currently working on a prototype program to test out some ideas the group has for our next iteration.  I ended up using Linq all over the place with no regard to optimizing the querys and my program runs quite fast.  So it seems that Linq doesn't slow down the code at all or at least not enough to notice.  Can't get better than that.

I have a feeling that Linq will become a fixture in my code from now on.

Comments