Tag | LINQ Posts

Last time I posted something regarding Converting IP Addresses to Decimal and Looping an IP Address Range The next step is to do something with those remote IP Addresses. The first thing that we can play with is to get some information from a remote host using Netbios Name Service. Some of the information that we can get using the class below are 1. Mac Address 2. Netbios Name (Computer Name) 3. Netbios Group (Workgroup name, Domain Name) 4. Netbios Username Below is the initial helper class I coded ...
First, create a class containing two members: value and id. Value is what is displayed in the combobox while id is associated with that value. I like to create a “global” class to contain properties and classes that is used through out the project. In this case, I have a class defined as clsCHTLCommon. In this class, I’ve defined this class: 1: using System; 2: using System.Collections.Generic; 3: using System.Linq; 4: using System.Text; 5: using System.Data; 6: using baseSql; 7: 8: namespace CHTL_HMI ...
This article is Part 3 of the series “Producing and Consuming OData in a Silverlight and Windows Phone 7 application.” You can read any of the parts you may have missed by clicking on the links below. Producing and Consuming OData in a Silverlight and Windows Phone 7 application. (Part 1) – Creating our first OData Data Source and querying data through the web browser and LinqPad. Producing and Consuming OData in a Silverlight and Windows Phone 7 application. (Part 2 ) – Consuming OData in a Silverlight ...
Previously we've talked about how to fetch the data from the database and populate the form with EF. In this example I'm going to demonstrate how to do Edit,Update and Delete operations in the form with Entity Framework. And oh since this is a continuation of my previous example I would suggest you to refer that first before you go any further. STEP 1: Setting up the UI Since this is a continuation of my previous example then I'm jus going to use the same layout and extend it a bit by adding some ...
In Part 1 we've talked about how to insert data to the database with Entity Framework. In this part I'm going to demonstrate how to fetch the data from the database and populate the form fields with Entity Framework. STEP 1: Setting up the Form To get started let's go ahead and fire-up visual studio and add a new WebForm. For the simplicity of this demo I just set up the form like this: <asp:Content ID="Content2" ContentPlaceHolderID="MainC... runat="server"> <asp:DropDownList ID="ddlUser" ...
Few months ago I wrote a series of articles regarding how to Insert, Update, Fetch and Delete data in the form using LINQ to SQL. You can view the series of articles below: Inserting Data to Database using LINQ to SQL Fetching Data from Database and Populating fields in the Form using LINQ to SQL Editing, Updating and Deleting Data in the Form using LINQ to SQL In this article I'm going to demonstrate the basics on how to work with MS Entity Framework. Basically in this part I'm going to show you ...
Over the last few days I’ve been coding away with several ORMS and code generators trying to find me one which I am comfortable with. Here is what I learn Not all ORMs are perfect! SubSonic Telerik OpenAccess nHibernate via Code smith Generator and LLBLGen LLBLGen Pro Framework SubSonic This is an awesome piece of work my Mr. Conery (and team)…for FREE! I’ve been using this for quite a while now. It is excellent for small projects, both Web and Winform apps. It’s a breeze to setup and get off and ...
I have a .Net 4.0 site that uses Entity Framework and Linq to SQL. After reworking a few tables and a few page operations, a new error appeared: "Row not found or changed". Every time I commit changes to a particular table, this error would be raised. From a quick review of msdn and the internet, the primary reason for this exception appears to be data concurrency issues - (The source data in the database is out of sync with the data you are attempting to update.) That did not apply to my development ...
This post is another in a series that will just contain little GUCs (Generic Utility Classes) I’ve developed along the way. If these already exist as part of the framework and I’ve overlooked them, feel free to let me know! And if you know of a better way to implement them, do the same! I’m never too old to learn something new (I hope!). I've blogged in the past about how useful the overlooked HashSet class can be (here) and about the very useful ToDictionary(), ToList(), and ToLookup() LINQ extension ...
If you hate being a mindless drone in some Illogical software sweatshop, switch to T4. Note that you cannot use reflection - you must use EnvDTE or your VS instance will lock. Use the T4Toolbox to access the current TransformContext to pull classes from files. Apply an iteration to generate properties in the target class that use the model source class for backing properties and change notification. It just works! <#@ templatedebug="true" hostSpecific="true" #> <#@ outputextension=".cs" ...
In this Issue: Roy Dallal, Rudi Grobler, Jeff Prosise(-2-), Jesse Liberty, Morten Nielsen, Derik Whittaker, Peter Torr, Xianzhong Zhu, and Adam Kinney. Above the Fold: Silverlight: "Silverlight: Adding Google Streets View" Roy Dallal WP7: "Using the accelerometer to control planar transforms on Windows Phone 7" Morten Nielsen Shoutouts: Andy Wigley posted this today from appamundi: Want a FREE Windows Phone?? From SilverlightCream.com: Silverlight: Adding Google Streets View Roy Dallal posted an ...
I've seen a few guys asking on stack overflow and forums how to order randomly using LINQ.
Here's a simple solution using Guid:

OrderBy(x => System.Guid.NewGuid())
I'm just getting to grips with MVC linq etc etc and came across what looks like a common stumbling block. For the more experienced of you reading this please refrain from shouting "Dumbass" at me. All the tutorials are either Code First examples or they create the database from scratch in the App_Data directory. All well and good for a tutorial that need to be easily portable to the readers computer, but not very helpful when setting up a full scale MVC application. My first problem was my lack of ...
(these are lifted verbatim from Microsoft here, here and here and are presented below only because it’s convenient to have them lumped altogether…) Getting Started with Windows Phone Windows Phone development platform supports both XNA Framework and Silverlight. This unit takes you through the step-by-step creation of your first Windows Phone Silverlight application. Hands-On Labs · Hello Windows Phone This lab intends to be the classic "Hello World" application, introducing you to the tools and ...
This article is Part 2 of the series “Producing and Consuming OData in a Silverlight and Windows Phone 7 application.” Producing and Consuming OData in a Silverlight and Windows Phone 7 application. (Part 1) – Creating our first OData Data Source and querying data through the web browser and LinqPad. Producing and Consuming OData in a Silverlight and Windows Phone 7 application. (Part 2 ) – Consuming OData in a Silverlight Application. Producing and Consuming OData in a Silverlight and Windows Phone ...
While I have been using Linq to Object for a couple of years now I had not investigated Linq to SQL up to this point. I figured I would put together my take on this technology’s use. Linq is a wonderful syntax for navigating an object graph without having to walk the graph object by object and member by member. It is concise and compact but for someone who has never seen its syntax you would swear you went from reading English to obscure mathematic notation. If you want to learn about the general ...
A recent project used Enterprise Library Validation to validate domain objects, and needed it configured for a web front end, a WCF front end, and (of course) unit tests. The same configuration in 3 different places didn't strike me as very DRY, so I figured hey - why not have it configure itself? Here's a quick paraphrase of how I did it. I started with an abstraction of the validation service:public interface IValidationService { bool IsValid<T>(T objectToValidate) where T : class; }...which ...
In this Issue: Roy Dallal, Mike Snow, Jesse Liberty, Chris Koenig, John Papa, Jeremy Likness, Michael Crump, Chris Rouw, and Beth Massi. Above the Fold: Silverlight: "Clean Design-Time Friendly ViewModels: A Walkthrough" Jeremy Likness WP7: "WP7 Insights #3: Storing User State - Activating and Deactivating" Chris Rouw Shoutouts: Shawn Wildermuth announced a new version of his "Phoney Tools": Phone Tools v0.6 Released - Breaking Change! ... breaking changes and some new stuff too. Takeshi Eto at DiscountASP.NET ...
Once again, in this series of posts I look at the parts of the .NET Framework that may seem trivial, but can really help improve your code by making it easier to write and maintain. LINQ has added so many wonderful extension methods to our .NET toolbox! In particular, there are a few methods that are useful for creating a collection from an IEnumerable<T> instance. The ToDictionary() and ToList() extension methods, for example, are handy for taking an IEnumerable<T> and creating a Dictionary ...
I have started a new series on SilverlightShow.net called Producing and Consuming OData in a Silverlight and Windows Phone 7 application. I decided that I wanted to create a very simple and easy to understand article that not only guides you step-by-step but includes a video and full source code. I personally believe this is the best way to teach someone something and I hope you enjoy the series. I also want to thank SilverlightShow for giving me this opportunity to help other developers get up to ...
Well, will you look at that - no sooner do I write my first blog about an extension method I've written for accessing deployed Assemblies and Types, than I discover today that it doesn't actually work quite how I intended it. Excellent! The issue is in scenarios where assemblies are copied into a deployment directory as and when they're needed, which I attempted to work around in the original version by calling GetTypes() on all the Assemblies which are found. That gave me the following problem: ...
In this Issue: Colin Eberhardt, XamlNinja, Andrea Boschin, Michael Washington, Michael Crump, Alex Knight, WindowsPhoneGeek, Jesse Liberty(-2-), Damon Payne. Above the Fold: Silverlight: "7Metro: Silverlight Theme" Alex Knight WP7: "Metro In Motion – Fluid List Animation" Colin Eberhardt Lightswitch: "LightSwitch Online Ordering System" Michael Washington Shoutouts: Laurent Bugion announced MVVM Light V4 preview 2 (BL0015) #mvvmlight Max Paulousky posts that The Prism Team Needs Your Help From SilverlightCream.com: ...
This code didn't quite work how I intended, so I've updated it in a follow up blog. So - first post - might as well start with an extension method of mine I've found rather useful recently. It returns a collection of Types from all locally-deployed Assemblies, optionally filtering by Assembly and Type. It's an extension method on Assembly, so if you wanted to get all the available Types which implement the IService interface, you could call IEnumerable<Type> services = Assembly.GetExecutingAssemb... ...
If you've been a loyal Reflector user, you've probably been exposed to the debacle surrounding RedGate's decision to no longer offer a free version. Since then, the race has begun for a replacement with a provider that would stand by their promises to the community. Mono has an ongoing free alternative, which has been available for a long time. However, other vendors are stepping up to the plate, with their own offerings. If Not Reflector, Then What? One of these vendors is Telerik. In their recent ...
Not too long ago, Microsoft released, NuGet, an automated package manager for Visual Studio. NuGet makes it easy to download and install assemblies, and their references, into a Visual Studio project. These assemblies, which I loosely refer to as packages, are often open source, and include projects such as LINQ to Twitter. In this post, I'll explain how to get started in using NuGet with your projects to include: installng NuGet, installing/uninstalling LINQ to Twitter via console command, and installing/uninstalling ...
LINQ und ArcObjects Motivation LINQ1 (language integrated query) ist eine Komponente des Microsoft .NET Frameworks seit der Version 3.5. Es erlaubt eine SQL-ähnliche Abfrage zu verschiedenen Datenquellen wie SQL, XML u.v.m. Wie auch SQL bietet LINQ dazu eine deklarative Notation der Problemlösung - d.h. man muss nicht im Detail beschreiben, wie eine Aufgabe, sondern was überhaupt zu lösen ist. Das befreit den Entwickler abfrageseitig von fehleranfälligen Iterator-Konstrukten. Ideal wäre es, natürlich ...
In this Issue: András Velvárt, WIndowsPhoneGeek(-2-), Jesse Liberty(-2-), Victor Gaudioso, Kunal Chowdhury, Jeremy Likness, Michael Crump, and Dhananjay Kumar. Above the Fold: Silverlight: "Application Library Caching in Silverlight 4" Kunal Chowdhury WP7: "Handling WP7 orientation changes via Visual States" András Velvárt Shoutouts: Joe McBride gave a MEF Head User Group presentation and has posted How to Become a MEF Head – Slides & Code From SilverlightCream.com: Handling WP7 orientation changes ...
Ever wanted to have a simple jQuery menu bound with ASP.NET web site map file? Ever wanted to have cool css design stuffs implemented on your ASP.NET data bound controls? Ever wanted to let Visual Studio generate logical layers for you, which can be easily tested, customized and bound with ASP.NET data controls? If your answers with respect to above questions are ‘yes’, then you will probably happy to try out latest release (v5.0) of Employee Starter Kit, which is intended to address different types ...
Yesterday I told Wang Tao, an annoying colleague sitting beside me, about how to make the static content enable the CDN in his website which had just been published on Windows Azure. The approach would be Move the static content, the images, CSS files, etc. into the blob storage. Enable the CDN on his storage account. Change the URL of those static files to the CDN URL. I think these are the very common steps when using CDN. But this morning I found that the new Windows Azure SDK 1.4 and new Windows ...

I released LINQ to Twitter Beta v2.0.20: http://goo.gl/1i97X.  Most of the items were bug fixes.  A couple items were new: Geo Search and I finished adding Asynch support for non-Silverlight APIs.

Joe

What does this code print and why? HashSet<int> set = new HashSet<int>(); int[] data = new int[] { 1, 2, 1, 2 }; var unique = from i in data where set.Add(i) select i; // Compiles to: var unique = Enumerable.Where(data, (i) => set.Add(i)); foreach (var i in unique) { Console.WriteLine("First: {0}", i); } foreach (var i in unique) { Console.WriteLine("Second: {0}", i); } The output is: First: 1 First: 2 Why is there no output of the second loop? The reason is that LINQ does not cache ...
I wanted to try to use T4 to read a web.config and generate all of the appSettings and connectionStrings as properties of a class. I elected in this template only to output appSettings and connectionStrings but you can see it would be easily adapted for app specific settings, bindings etc. This allows for quick access to config values as well as removing the potential for typo's when accessing values from the ConfigurationManager. One caveat: a developer would need to remember to run the .tt file ...
LINQPad is a popular utility for .NET developers who use LINQ a lot. In addition to standard SQL queries, LINQPad also supports other types of LINQ providers, including LINQ to Twitter. The following sections explain how to set up LINQPad for making queries with LINQ to Twitter. LINQPad comes in a couple versions and this example uses LINQPad4, which runs on the .NET Framework 4.0. 1. The first thing you'll need to do is set up a reference to the LinqToTwitter.dll. From the Query menu, select query ...
In this Issue: Robby Ingebretsen, Victor Gaudioso, Andrea Boschin(-2-), Rudi Grobler(-2-), Michael Crump, Deborah Kurata, Dennis Delimarsky, Pete Vickers, Yochay Kiriaty, Peter Kuhn, WindowsPhoneGeek, and Jesse Liberty(-2-). Above the Fold: Silverlight: "Silverlight Simple MVVM Printing" Deborah Kurata WP7: "Creating theme friendly UI in WP7 using OpacityMask" WindowsPhoneGeek Tools: "KAXAML v1.8" Robby Ingebretsen Shoutouts: Peter Foot posted Silverlight for Windows Phone Toolkit–Feb 2011 Rudi Grobler ...
In this Issue: Rob Eisenberg(-2-), Gill Cleeren, Colin Eberhardt, Alex van Beek, Ishai Hachlili, Ollie Riches, Kevin Dockx, WindowsPhoneGeek(-2-), Jesse Liberty(-2-), and John Papa. Above the Fold: Silverlight: "Silverlight 4: Creating useful base classes for your views and viewmodels with PRISM 4" Alex van Beek WP7: "Google Sky on Windows Phone 7" Colin Eberhardt Shoutouts: My friends at SilverlightShow have their top 5 for last week posted: SilverlightShow for Feb 14 - 20, 2011 From SilverlightCream.com: ...
Hi and welcome! I'm a software developer and this is my geeks blog. I have 20 years Visual Studio mainly C++, MFC, ATL and now, thankfully, C# and I am embarking on the new world (well new to me) of WPF, so I thought I would try and capture my successful...and not so successful...WPF experiences with the geek world. So where to start? WPF? What I know so far... From wiki..."Windows Presentation Foundation (or WPF) is a graphical subsystem for rendering user interfaces in Windows-based applications." ...

I am evaluating Linq to SQLProfiler.  I have found better ways to do things within minutes.  It helps you optmize you Linq.  You will not regret investing the time to learn the tool, which is easy BTW.

 

In my previous post, I introduced my problem, but I didn’t explain the problem with Entity Framework When you try the solution indicated you will take the following error: LINQ to Entities don’t recognize the method 'System.String Join(System.String, System.Collections.Generic.... of the method, and this method can’t be translated into a stored expression. The query that produces that error was: 1: var consulta = (from TCabecera cab in 2: contexto_local.TCabecera 3: let ...
PROBLEM Firstly, I am working on a project based on LINQ, EF, and C# with VS2010. The following Table shows what I have and what I want to show. Header C1 C2 C3 1 P1 01/01/2011 2 P2 01/02/2011 Details 1 1 D1 2 1 D2 3 1 D3 4 2 D1 5 2 D4 Expected Results 1 P1 01/01/2011 D1, D2, D3 2 P2 01/02/2011 D1,D4 IDEAS At the begin I got 3 possible ways: - Doing inside the DB: It could be achieved from DB with a CURSOR in a Stored Procedure. - Doing from .NET with LOOPS. - Doing with LINQ (I love it!!) FIRST ...

I would like to thank Dave Noderer and Rainer Habermann and the rest of the team for a successful code camp!  Thanks to the attendees of my Linqq to SQL class as well.  I will be sending out the emails tonight with the information I promised.

Ed

In this Issue: Mark Monster, Jaime Rodriguez, Mark Hopkins, WindowsPhoneGeek, David Anson, Jesse Liberty, Jeremy Likness, Martin Krüger(-2-), Beth Massi, Joost van Schaik, Laurent Bugnion, and Arik Poznanski. Above the Fold: Silverlight: "Parsing the Visual Tree with LINQ" Jeremy Likness WP7: "Silverlight-ready PNG encoder implementation shows one way to use .NET IEnumerables effectively" David Anson Lightswitch: "How to Send Automated Appointments from a LightSwitch Application" Beth Massi Shoutouts: ...

Having read through the ".Net Class Library" and onto the section on LINQ I continue to be favourbly impressed by this book.

One important point about this book, you can just dip into sections rather than just read from start to finish.

I was impressed by the write up on the various collections. After reading the chapters on LINQ, I am looking forward to getting Adam Freeman's book on LINQ.

An open source library and full product have been developed for transparently splitting large tables across several databases for performance, similar to database table partitioning. It is all handled along with the Linq to SQL framework, and looks pretty slick, I will be reviewing the product shortly. It looks mostly transparent to the developer! There are other capabilites worth a look. This looks like it works for azure as well. Here are some links: http://enzosqlshard.codeple... http://enzosqlbaseline.com ...
Sorry for the long blogging hiatus. First it was, of course, the holidays hustle and bustle, then my brother and his wife gave birth to their son, so I’ve been away from my blogging for two weeks. Background: Finding an item’s index in List<T> is easy… Many times in our day to day programming activities, we want to find the index of an item in a collection. Now, if we have a List<T> and we’re looking for the item itself this is trivial: 1: // assume have a list of ints: 2: var list = ...
Once again we consider some of the lesser known classes and keywords of C#. Today we will be looking at two set implementations in the System.Collections.Generic namespace: HashSet<T> and SortedSet<T>. Even though most people think of sets as mathematical constructs, they are actually very useful classes that can be used to help make your application more performant if used appropriately. For more of the "Little Wonders" posts, see the index here. A Background From Math In mathematical ...
I’ve had to look this up a couple of times, and there’s not much out there, so I end up guessing the same answer over and over. When using MethodBase.GetParameters() to get an array of ParameterInfo object, I often want to get a count of the number of parameters that are out, optional, params, etc. For out and optional, you can simply check ParameterInfo.IsOut or ParameterInfo.IsOptional or any number of other “Attributes”. However, for params, there isn’t a property on ParameterInfo. Instead, you ...
In this Issue: Max Paulousky, Renuka Prasad, Ollie Riches, Jesse Liberty(-2-, -3-, -4-, -5-), Medusa M, John Papa, Beth Massi, and Joost van Schaik. Above the Fold: Silverlight: "Stop What You Are Doing And Learn About Reactive Programming" Jesse Liberty WP7: "Windows Phone Looping Selector for Digits " Max Paulousky Lightswitch: "How To Send HTML Email from a LightSwitch Application" Beth Massi Shoutouts: Shawn Wildermuch has niether GooNews for users of his cool WP7 app or or for the WP7 Marketplace ...
A few months ago I blogged about using Model metadata to render a dynamic UI in MVC 2. The scenario in the post was that we might have a view model where the questions are conditionally displayed and therefore a dynamic UI is needed. To recap the previous post, the solution was to use a custom attribute called [QuestionId] in conjunction with an “ApplicableQuestions” collection to identify whether each question should be displayed. This allowed me to have a view model that looked like this: 1: [UIHint("ScalarQuestion")] ...
The build process template and custom activity described in this post is available here: http://cid-ee034c9f620cd58d... Running code metrics has been available since VS 2008, but only from inside the IDE. Yesterday Microsoft finally released Visual Studio Code Metrics Power Tool 10.0, a command line tool that lets you run code metrics on your applications. This means that it is now possible to perform code metrics analysis on the ...
Fear, it’s what turns maintaining applications into a nightmare. Technology moves on, teams move on, someone is left to operate the application, what was green is now perceived brown. Eventually the business will evolve and changes will need to be made. The approach to those changes often dictates the long term viability of the application. Fear of change, lack of passion and a lack of interest in understanding the domain often leads to a paranoia to do anything that doesn’t involve duct tape and ...