“Contains” with LINQ to Entities

By James at April 22, 2011 21:40
Filed Under: Entity Framework

This post is mostly so I don’t forget, but if it helps you, then that’s groovy too.

In SQL you can use the IN clause to find a bunch of files where say the Id number is IN(1,2,3,4,5,6). However there isn’t that capability using LINQ to Entities.

I need this functionality for a project I’m working on and ran across some Bing results which gave me some ideas. Here’s how I did it.

 

var ressFileList = _db.RessFiles.AsEnumerable().Where(db => _ressFileIds.Contains(db.Id)).ToList<RessFile>();

 

Where _ressFileIds is a list I’ve generated elsewhere. The key is to use AsEnumerable() when calling the table you want to find the Id values in. Works like a champ.

James

Watch out! Visual Studio SP1 Pack for VS and VWD with WPI

By James at April 14, 2011 20:18
Filed Under: ASP.NET, Beta Software, Entity Framework, Miscellaneous, Technology in General

I like to have all my tools updated and current and wanted to install the RTM version of IIS 7.5 Express, SQL Server Compact 4.0 with the tools, and Web Deploy 2.0. I found a link to install these, along with Visual Studio 2010 SP1 via the Web Platform Installer. http://www.microsoft.com/web/gallery/install.aspx?appid=VWDorVS2010SP1Pack

Ok, methinks, I already installed VS 2010 SP1, so this should be smart enough to see this and not muck things up. Boy was I mistaken. After 90 minutes of installing, I figured something was wrong and cancelled the installation. Man, was that ever a bonehead move! My entire development environment got hosed; currently working solutions wouldn’t open, MVC 2/3 templates were gone, lots of frustration. Running SP1 again, I was given the opportunity to repair the installation, and that failed…twice.

I finally uninstalled VS 2010 SP1, uninstalled VS 2010, then reinstalled both. However, now this time, the Entity Framework templates were missing, and opening an EDMX file just showed the XML. Yikes.

I did another round of uninstall/reinstall, only to find out that both versions of MVC 2 and 3 didn’t have the tooling and my current MVC2 project doesn’t recognize any MVC related code.

I keep my VS 2010 .iso files on my server and use a virtual CD drive to run them. Doing a repair this way, caused a ton of problems too, as the VS 2010 installer wants to install .NET 4.0, which wants to reboot the system. Naturally when the system reboots, the installer wants to find the setup files, but since it takes time to find all the drives after a reboot, the install keeps failing.

What a waste of a day and a half.

Lessons learned

1. Don’t use the VS SP1 Pack for VS and VWD from the Web Platform Installer. Get the individual downloads for the apps you want to install (IIS 7.5, SSCE and Web Deploy 2.0) and run them by themselves.

2. Copy the files from the VS 2010 .iso to a local folder and run the setup from there. This way after a reboot, the installation will know where to look to continue on.

3. If it ain’t broke, don’t fix it.

Sigh….

Silverlight Grid for Easy Data Visualization

By at October 28, 2010 15:09
Filed Under: Entity Framework, FlexGrid

My recorded webinar, "Silverlight Grid for Easy Data Visualization" is up on Vimeo. You can see it here, http://www.vimeo.com/16241316. And as promised I've uploaded the Slides and Code. You can get them in the attachments.

Thanks for listening.... Happy Programming,

James

 

About the author

James James is a five time and current Microsoft MVP in Client App Development, a Telerik Insider, a past Director on the INETA North America Board, a husband and dad, and has been developing software since the early days of Laser Discs and HyperCard stacks. As the Founder and President of the Inland Empire .NET User's Group, he has fondly watched it grow from a twice-a-month, early Saturday morning group of five in 2003, to a robust and rambunctious gathering of all types and sizes of .NET developers.

James loves to dig deep into the latest cutting edge technologies - sometimes with spectacular disasters - and spread the word about the latest and greatest bits, getting people excited about developing web sites and applications on the .NET platform, and using the best tools for the job. He tries to blog as often as he can, but usually gets distracted by EF, LINQ, MVC, ASP, SQL, XML, and most other types of acronyms. To keep calm James plays a mean Djembe and tries to practice his violin. You can follow him on twitter at @latringo.

And as usual, the comments, suggestions, writings and rants are my own, and really shouldn't reflect the opinions of my employer. That is, unless it really does.

James Twitter Feed

Recent Comments

Comment RSS

Month List