[dba-Tech] LINQ -- Was Free OneNote

Steve Erbach erbachs at gmail.com
Fri Mar 21 16:20:16 CDT 2014


Paul,

I'm still ramping up with LINQ, but here are the high points:


   - "Upside down SQL statement"...yes, that's the way it looks. It was
   done to allow querying of any data source, including array objects,
   collections, etc. SQL Server is simply one source for the data. LINQ lets
   you query almost any object that has data in it.
   - In Visual Studio you may take advantage of the Object Relational
   Modeler (I think that's what it's called). You open the Server Explorer,
   connect to SQL Server, and "drag" tables onto the ORM design "surface". If
   your tables are linked by foreign keys, the ORM designer will automagically
   connect the dots, similarly to the query design tool in SSMS. This is
   significant because...
   - Once you save the ORM design as a Visual Studio object (it goes into
   the App_Code folder, I believe) it sets up a new DataContext class that
   contains all the tables in your ORM. So when you create a LINQ query from
   an instance of that class, your tables' fields become properties of the
   DataContext table object complete with Intellisense. It makes for quite a
   bit less work than setting up SQL strings.
   - Then the results of the LINQ query are stored in an IEnumerable object
   that can be looped through.
   - LINQ syntax includes the concept of chaining operators, just as
   methods can be chained in C# or VB. This makes for very flexible and
   concise query statements. E.g., in C#, the following code creates a string
   array and then manipulates it in a LINQ query, using WHERE, ORDERBY, and
   SELECT clauses which themselves use the .NET functions Contains, Length,
   and ToUpper:

   string[] names = { "Tom", "Dick", "Harry", "Mary", "Jay" };

   IEnumerable<string> query = names
   .Where (n => n.Contains ("a"))
   .OrderBy (n => n.Length)
   .Select (n => n.ToUpper());

   foreach (string name in query) Console.WriteLine (name);

I could go on...and I could certainly go on about LINQPad...a great way to
learn LINQ, by the way. And its ability to serve as a scratchpad/sandbox
for .NET applications -- not just for LINQ queries but for any kind of VB
or C# or F# code -- is very very handy.

-- 
Regards,

Steve Erbach
Neenah, WI


On Fri, Mar 21, 2014 at 2:19 PM, Paul Hartland <paul.hartland at googlemail.com
> wrote:

> oohhh was just going to post a bit about LINQ, if I am coding an
> application in vb.net or when I get round to learning it ASP.net are there
> any advantages of using LINQ over SQL selects etc for data, not really
> looked into LINQ but does just look like an upside down SQL statement...
>
> Paul
>
>
> On 21 March 2014 18:23, Steve Erbach <erbachs at gmail.com> wrote:
>
> > Arthur,
> >
> > >>  I use OneNote not *as* a development editor, but more like a  library
> > <<
> >
> > Not a bad idea at all.
> >
> > >> ... the notebook contains a lot of code posted by various  listers on
> > the AccessD list. <<
> >
> > Ever think of making that available? Sounds like a fine resource.
> >
> > You just made me think of something with your discussion of code
> > repositories/libraries. I have recently begun using LINQ more in my .NET
> > projects. There is a utility written by Joseph Albahari called LINQPad.
> > Have you heard of it? If not, you may want to download it and give it a
> > try. I purchased the Premium edition ($59 or so) because I was so
> impressed
> > by it. LINQPad is one of the best utilities I've ever used.
> >
> > It doesn't just allow you to write LINQ statements. It's a sandbox for
> C#,
> > VB, and F# code. If you're working on an algorithm in a .NET project,
> > LINQPad is great for trying out the code without having the overhead of
> > Visual Studio and a full-fledged .NET project to encapsulate your code.
> >
> > It's also a fully functional SQL Server front-end. While it doesn't have
> > the Intellisense capabilities of SSMS (unless you write LINQ statements),
> > it does offer something interesting if you're willing to put a bit of
> time
> > into LINQ.
> >
> > That is, if your SQL tables have foreign key relationships to each other,
> > the results of a LINQ query of a top-level table will present drill-downs
> > into the subsidiary tables, kind of like the way that Access does it. The
> > results are presented in HTML and you can drill down and back up in the
> > result of a LINQ query to see all the aspects of your result set with
> > respect to the linked tables.
> >
> > It's a fine utility, one I'm very glad to have paid to get the full
> > version.
> >
> >
> >
> > On Wed, Mar 19, 2014 at 9:06 AM, Arthur Fuller <fuller.artful at gmail.com
> > >wrote:
> >
> > > Steve,
> > >
> > > Actually, I use OneNote not *as* a development editor, but more like a
> > > library. I have NoteBooks for several programming languages such as VBA
> > and
> > > Javascript and SQL, each of which has sections such as DAO and ADO and
> > > Strings in the case of VBA, and each of these sections has a collection
> > of
> > > pages containing one function or group of related functions per page.
> > This
> > > approach has enabled me to save a lot of code into an organized
> library;
> > in
> > > the case of VBA, the notebook contains a lot of code posted by various
> > > listers on the AccessD list.
> > >
> > > OneNote is also terrific for the mundane aspects of a development
> > project:
> > > meeting notes, telephone conversations, subjects to research, hours
> > worked,
> > > etc. Everything is all in one place, all loaded at once as soon as that
> > > notebook is opened. No more trying to remember what was said in a phone
> > > call a week or two ago: as long as my notes taken at the time of the
> call
> > > were accurate (Skype and a headset enable me to type during the call,
> > > rather than afterwards).
> > >
> > > Arthur
> > >
> > > P.S.
> > > OneNote is excellent for non-work-related topics such as Recipes, too.
> My
> > > sister-in-law once called me asking for ideas for new recipes -- I sent
> > her
> > > my OneNote book containing several hundred recipes, all organized by
> > > category (chicken, beef, soups, vegetarian, etc.) Almost all of these
> > were
> > > pasted from emails sent to me by email from recipes.com and elsewhere.
> > >
> > >
> > > On Wed, Mar 19, 2014 at 9:43 AM, Steve Erbach <erbachs at gmail.com>
> wrote:
> > >
> > > > Arthur,
> > > >
> > > > I've been using OneNote for a year or so at work. I remembered being
> > very
> > > > puzzled by the lack of a search-and-replace capability. I spent time
> > > > looking for it and searching for solutions on-line. It hasn't
> hampered
> > me
> > > > too much, but it's odd.
> > > >
> > > > I certainly like it for note taking, list making, idea starting, and
> > > > organizing snippets and emails and web page clips.
> > > >
> > > > It's one of those things that you just have to use to discover its
> > > > usefulness. E.g., the "Recent Edits" feature. I stumbled on that one
> > and
> > > > it's quite useful. I wish there were something like that for
> > development,
> > > > say, where one might not remember every single class or module that
> one
> > > > changed in the past x days.
> > > >
> > > >
> > > >
> > > > On Tue, Mar 18, 2014 at 3:41 AM, Arthur Fuller <
> > fuller.artful at gmail.com
> > > > >wrote:
> > > >
> > > > > In my opinion, among Microsoft's plethora of software offerings,
> > > OneNote
> > > > is
> > > > > an unsung hero. I love this program and consider it indispensable.
> > > > >
> > > > > MS has now made it available for free to Windows and Mac users. You
> > can
> > > > > read about it here:
> > > > >
> > > > >
>


More information about the dba-Tech mailing list