Dynamic Linq where query

I just wanted to quickly share a pretty nice article about dynamic where predicates in Linq. It requires a little class to make AND and OR combinations with different predicates. The result is a flexible dynamic way of building a where predicate. Linq generates pretty good and effective queries from the predicates. Very nice!




Crawling phpBB or other forms based apps with SharePoint

Out-of-the-box, the Microsoft Office SharePoint Server comes with a search engine, which is the 2008 Search Server. It’s capable of crawling different content sources via http, by requesting the page, indexing it and visiting links on the page after that if you prefer to.

Now within SharePoint sites this is all pretty straightforward. The crawling of internet websites is also pretty easy, as long as they allow anonymous access or support NTLM (Integrated Windows) authentication. It becomes different when you want to index a web application protected by a forms based username and password, like a phpBB forum (and loads of other php based sites).

For this purpose, Microsoft released a hotfix and a downloadable application which update the crawl rules API in order to allow this.

Read More

.NET Framework 2.0 related DataSet bug

These last couple of days, we’ve been working on fixing a bug. The application it occured in works together with a Progress proxy object which talks to a Progress database. Because that link isn’t too transparant, it was very difficult tracing the bug and finally coming up with a solution for it.

The problem occured on merging a dataset into another dataset. That would throw the most dreaded ‘System.Data.ConstraintException: Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.’ exception, feared by anyone who has ever used the .NET DataSet.

The weird thing was this bug wasn’t occuring on my own and my colleague’s machine. Offcourse it popped up at the customers’ site and blocked their application. We first thought an environment issue on the server could be causing this. After ruling that out we went looking on the client side. It seems the .NET 2.0 Framework contains a bug concerning DataSets and merging which is fixed in SP1 of that same framework. We found out after comparing the Framework versions on machine which did and didn’t work, the SP1 update was the only difference. After installing SP1 everything worked well.

I hope I might save someone a couple of days of debugging. Install all framework SP’s before searching your own code 😉

.NET Framework related downloads are found here.

Adding a column to SharePoint news articles (design/edit view)

The ‘News site’ site template of MOSS 2007 is probably one of the most used templates for companies which use SharePoint for their internal intranet. It allows you to add news items to a specifically designed site in a user friendly way. Editing the news items is done on the page itself, with extra functions for checking in/out pages, publishing concept and final versions and much more.

One of the questions many people asked me is: “Is it possible to add extra columns to the default news site?”. Offcourse it is! Just go to the article pages document library and add a new column. Unfortunately there’s one little problem with that approach: your newly added column won’t show on the ‘edit  page’ but only on the document properties page. That’s not cool, since your users would have to switch back and forth between the ‘edit page’ layout and the document properties to fill in all columns. You would much rather add the column to the ‘edit page’ layout and perhaps show it on the article too, right?

Read More

Inter-application communication with WCF webservices

Unfortunately for me (but not unfortunately at all I guess), not all software developed right now is .NET based. That’s fine because there are a lot of other really good alternatives out there which do the trick and in some cases even do the same trick even better. And even when a .NET based application seems to be a better choice, there are a lot reasons why you’ll still want to develop a non-.NET app. For instance: let’s say we’ve got an big application developed in Java, Oracle or Progress. It makes sense that new requirements made by your customer will end up being developed in the same language/environment used for building the main app, right?

But how about giving the new part of your application a modern “Office style” look? Using .NET with some 3rd party components that’s a piece of cake, but not all development environments offer the possibility of developing nice looking applications. And I’m not even talking about all really nice framework parts which are available in .NET development.

A possibility would be to create the new ‘module’ of your application using .NET, but that would (in most cases) require some-kind of communication mechanism between the ‘main app’ and your module. Now with .NET 3.0 that’s possible and made easy for you using webservices!

Read More

VS Designer throwing ‘Operation could not be completed’ error.

Today, while working with the Linq designer, my Visual Studio installation started throwing errors at me. They stated ‘Operation could not be completed’ followed by some Dutch nonsence which didn’t help much.

At first, I thought this had to do with me altering the database structure and then opening the Linq designer again. I tried deleting some of the altered tables in the designer files, but that didn’t help. Then I (quite randomly) clicked the database connection in the Server Explorer. It threw another error stating the application event log was full. I checked and that message was correct. After clearing the log, the errors disappeared and everything worked well again. So when you encountred this error: clear your application event log!

LinqDataSource not deleting records

I ran into a small problem using the LinqDataSource as a datasource for a GridView or ListView (the new 3.5 ListView features quite nice functionality, with an insert-capable grid!).

I had set up a datasource with a ListView bound to it which had a button per row to call the ‘Delete’ command. The other commands seemed to work fine (insert, edit) but the delete command didn’t do anything. Just a postback; no exception, no deletion, nothing.

After a lot of debugging, I found out I had set the primary key of my Linq object to be ‘readonly’. I had done this to prevent users from altering the PK and thereby breaking the database. Since the primary key was a generated uniqueidentifier anyway, I didn’t want my users to mess with it.

Anyway; after removing this setting (thus setting it not to be read-only), it suddenly deleted records just as I wanted it to.

The designer’s description for the Read Only setting is: “Controls whether an a set accessor is generated.”. That’s because each column/members get’s its own property with a get/set accessor. I’m not quite sure why this disables the possibility of deleting an object. Perhaps because you can’t create the object without setting it’s primary key, which makes sence. But then again; how is the object populated from the database with the correct private key and why is that method not used to populate it again on postback? Better yet: I would suppose the entire object is stored somewhere in the viewstate between postbacks so the primary key should be in there somewhere, right?

I’m not quite sure about why, but I do know you’d better leave your primary key not be read-only, unless you never want to delete that object.

More Linq to SQL

If you’re into ASP.NET and you want to learn Linq to SQL to provide your user with data from your SQL database, you need Scott Guthrie. And if you don’t know that name yet, you should definitely check out his blog.

For his articles on Linq to SQL, please check out these links:

Free stuff from Microsoft

Surfing around the web I stumbled upon this blogpost from Mohamed Ahmed Meligy writing about free stuff from MS. I thought this would be somekind of action I missed out on and was already too late to sign up for. But no! I tried and this link still takes you to a Microsoft site which requires you to enter your live ID and enter all the profile stuff you’ve probably entered 1000 times already. But after you do that, there are three e-books, one of which is complete, downloadable for free. They’re:

– Introducing Linq
– Introducing ASP.NET AJAX
– Introducing Silverlight 1.0

The Linq one is free in it’s entirety, so no need to buy it anymore. Thanks Microsoft and thanks Mohamed for putting it out there!