Archives
-
MongoDB with .NET – Part 1
MongoDB is one of the most popular NoSQL databases out there, and for good reasons. For once, it does not have some of the limitations of more recent ones – I’m thinking of DocumentDB and Azure Table Storage, I really don’t know about the others –, is easy to get started with, and yet supports advanced scenarios, such as clustering and replication. Of course, it is also free and has an open source C# API!
-
Entity Framework 7: What’s New?
The Microsoft WebCamp 2015 event (Portugal) is now over! Another day packed with lots of interesting sessions and, above all, interesting people!
-
Packt Publishing Thanksgiving Sales
-
ASP.NET 5 Node Services
At the MVP Global Summit, Steven Sanderson (@stevensanderson) presented a Microsoft project he was working on: Node Services. In a nutshell, this is an integration of ASP.NET 5 and Node.js, it makes it possible to call a Node.js function from ASP.NET. One of its possible usages is to use Node.js to compile AngularJS directives or ReactJS JSX files, and for that reason, there are two modules built on top of Node Services just for that purpose (code available at GitHub and NuGet, here and here).
-
Packt Publishing – 5$ Skill Up Year in Review
Skill Up: Year in Review
Back in June, we asked you what tech skills you were using most and what you were hoping to learn in the coming months. Over 20,000 of you replied and helped us to produce the most informative salary and skills reports of 2015.
Almost 6 months later, we want to find out what has changed, to get your thoughts on the most important emerging tech for 2016 and to, ultimately, help you to Skill Up into a new year.
Take our quick 5 minute survey and you will receive a code for buying any eBook or video for just $5!
-
Entity Framework Pitfalls – Composite Primary Keys
When you have a composite primary key, you will get two properties on your POCO class that together represent the id. In this case, conventions won’t be enough, so you need to mark both properties with the KeyAttribute attribute:
-
ASP.NET 5 View Components
One of my favorite features in ASP.NET 5 / MVC 6 is View Components. Like I said of Tag Helpers, I think they are what MVC was missing in terms of reusable components.
-
Using ASP.NET 5 Tag Helpers and the Bing Translator API
Update: In the latest version of ASP.NET 5, the GetChildContextAsync, that was previously available in the TagHelperContext class, is now in TagHelperOutput.
-
Throwing Exceptions and Keeping the Stack Trace
Since its beginning, C# offered two ways to rethrow an exception in a catch block:
-
The Evolution of .NET Dependency Resolution
Dependency Resolution (RS), Dependency Injection (DI) and Inversion of Control (IoC) are hot topics nowadays. Basically all frameworks are aware of it, or offer some mechanisms to help implement it. It all started a long time ago, however, and things are slightly confusing at the moment – but will get better!
-
Visual Studio Tips 3
Updated: see the fourth post here.
-
Persisting SignalR Connections Across Page Reloads
I recently had the need to keep a SignalR connection even if the page would reload. As far as I know, this cannot be done out of the box, either with hubs or persistent connections. I looked it up, but could find no solid solution, so here is my solution!
-
Unity, Part 11: Integrating With Azure Application Insights
Another one for the Unity series.
-
Correlation Id Scope
A correlation id is an enterprise messaging pattern that helps bind together several messages. If they have the same correlation id, then they must be somehow related. Several servers and service bus frameworks, such as SharePoint and NServiceBus, use this concept.
-
Elastic Object Implementation in .NET
I think it was Anoop Madhusudanan (aka, amazedsaint) who first coined the term “Elastic Object”. He even built an implementation, which you can find on GitHub and NuGet, which is very nice. Basically, it’s a class that allows adding members to its instances dynamically; this is a widely known pattern in scripting languages such as JavaScript, but not so easy to implement in .NET.
-
Data Platform Airlift 2015
Today I had the great pleasure to attend the Data Platform Airlift 2015 event, at Microsoft Portugal! Moreover, I presented a session together with Luís Calado on what’s new in the Azure world! My part was specifically about DocumentDB, one of Microsoft’s offers in the field of NoSQL.
-
Type Converter to Type
What happens when you need to pass a type as a string? Well, if the string is an assembly qualified type name, and if the assembly is either in Global Assembly Cache or in a known location – such as the Bin folder or a probed path – you’re likely to succeed. But, what if that isn’t the case? Well, we can follow these steps:
-
Custom .NET Data Provider
-
Ongoing Series of Posts
So, for your – and my – information, these are the post series currently going on in my blog:
-
Lesser-Known NHibernate Features: Executable HQL
What happens when you need to bulk change a lot of records on the database? The unwary novice might be tempted to load data from the database into class instances, change them and then either rely on change tracking to eventually make the changes persistent or even worse, explicitly do an update on every possibly changed entity. The non-novice readers should now rolling their eyes.var records = session.CreateQuery("update Person p set p.Email = p.Email + p.Username + '@somedomain.com' where p.Email is null").ExecuteUpdate();
-
Entity Framework Pitfalls: DbConfiguration Classes Are Automatically Loaded
Entity Framework, since version 6, allows us to specify certain aspects of its configuration by code through a DbConfiguration-derived class. This configuration can be specified in one of three ways:
-
Java Flaws
One thing I didn’t talk about in my Java vs C# series (by the way, more to come soon) was some things that I think Java got wrong.
-
Entity Framework Pitfalls: Using Stored Procedures for Basic Operations
Entity Framework, as of version 6, allows the usage of stored procedures for its CUD (Create, Update and Delete) operations. We just need to override the DbContext’s OnModelCreating method and call MapToStoredProcedures.
-
Entity Framework Pitfalls: Lazy Loading and Proxy Creation
There are two properties that control the ability to lazy load navigation properties:
-
ASP.NET Multitenant Applications Succinctly Released
-
Blend for Visual Studio 2012 by Example: Beginner’s Guide Discount Offer
I recently published a review of Pack Publishing’s new book, Blend for Visual Studio 2012 by Example - Beginner’s Guide. Well, guess what, Pack is offering a 50% off discount if you buy it between 17th and 25th of September! You just need to use this discount code:
-
Local Machine Interprocess Communication with .NET
TL; DR; A description of several techniques to pass messages between processes running on the same machine.
-
Blend for Visual Studio 2012 by Example Review
I was recently asked by Packt Publishing to review another of their books. This time it was Blend for Visual Studio 2012 by Example, a book by Abhishek Shukla (@abbeyshukla), apparently, the first book on Blend for Visual Studio, even if it still covers Visual Studio 2012, most of it will apply to 2013 as well. My interest in Blend came from the fact that I recently had to work with Silverlight, and Blend is, of course, one of the must-have tools.
-
Interception in .NET – Part 2: Dynamic Interception
This is part two of a series of posts on interception in .NET. You can find the first part here and the third here.
-
Interception in .NET – Part 1: Introduction
Update: see part two here.
-
Skill Up - Learn More to Earn More
PACKT Publishing made freely available its Skillup Reports: basically, it is a set of comprehensive reports for different technical areas - web development, app development, data development, sys admin - with lots of useful insights on these areas, focusing on skills and salaries. These are available on PACKT's site, so have a look!
-
Profiling SQL Server in .NET
The main tool for profiling SQL Server is, of course, SQL Server Profiler. You can, however, achieve more or less the same results using .NET, I'll show you how.
-
SharePoint Pitfalls: GUID Formats
SharePoint uses GUIDs extensively. The problem is, it accepts them in different formats, in different locations:
-
SharePoint Pitfalls: Master Pages in Page Layouts
When you deploy a page layout, you may want to add your own master page as well. I find it useful to add my own custom master pages and reference them directly, in the same or a dependent feature. You might be surprised, however, that it doesn’t work exactly how you’d expect!
-
SharePoint Pitfalls Index
Updated on July 20th
-
SharePoint Pitfalls: Publishing Pages in Document Libraries Other Than Pages
This one is a classic: the SharePoint Publishing feature in a Publishing Site creates a document library by the name of Pages; this is where you can store your publishing pages.
-
Case Study: Comparing ASP.NET Web Forms and MVC Implementations
Apparently, I am the last ASP.NET Web Forms developer in the whole World, which makes me kind of sad… anyway, after much crying, I decided to try out something: a comparison of Web Forms and MVC to solve a real life problem! Now, I only needed a problem to solve… Then, a colleague of mine came questioning me about captchas, so I thought, why not use it as my example? And here we are!
-
Automating Microsoft Azure with PowerShell Review
-
What’s New in C# 6.0
Visual Studio 2015 will be officially RTM on July 20th, Microsoft announced. With it comes a new version of the .NET framework (actually, two), .NET 5.0, and inside of it, support for a new version of the C# language, C# 6.0. Yeah, the numbers don’t match, keep that in mind!
-
Generating GDI+ Images for ASP.NET MVC Views
This post is about applying the same technique I presented for ASP.NET Web Forms, but this time for MVC.
-
Farewell, ASP.NET Web Forms, We Hardly Knew Ye
ASP.NET Web Forms, the venerable web framework that Microsoft shipped with the .NET framework almost 15 years ago and we all
hatelove, is going away. Yes, it’s official: ASP.NET 5 will not include Web Forms, only MVC 6. ASP.NET 4.6, however, will still include Web Forms, including some updates, but the future appears to be all MVC (and OWIN, for that matter). Having spend a lot of my professional life working with Web Forms, I feel kind of sad. Yes, I do acknowledge event-hell, viewstate-hell, etc, but I find it easy to get around this once you know a thing or two. But what I really like about Web Forms is the reuse capacity that server-side controls offer: just add a reference to an assembly containing controls, register them in Web.config or in the page, and you’re done. A control encapsulates both client and server-side logic, so it is the perfect reusability mechanism for the web, in my opinion, and I wrote tens of posts on it. MVC now offers somewhat similar mechanisms, in the form of view components and tag helpers, but before that, there was really no reuse mechanism – partial views cannot be referenced from an assembly and helper methods cannot be extended. Don’t get me wrong: I like MVC, but I think that Web Forms was complementary. Taking in consideration the extensibility mechanisms offered by MVC, I can imagine that someone will even implement Web Forms on top of it! -
SharePoint Pitfalls: Save Publishing Site as Template Option Missing
If you want to save a publishing site as a template, so that it can be used to create other sites, you may find it surprising that the option is missing from the site settings page:
-
SharePoint Pitfalls: Creating a Visual Studio Project Without SharePoint Locally Installed
This is the first on a (huge) collection of posts on SharePoint pitfalls. Hope you enjoy, and, please, do send me your feedback!
-
Sessão Netponto: Entity Framework 7
A minha apresentação sobre Entity Framework 7 feita na 6ª reunião presencial da Netponto em Coimbra está disponível aqui.
-
Entity Framework Pitfalls: Table Valued Functions
As of Entity Framework 6.x, Table Valued Functions are not supported, which is really a pity.
-
Open Source @ Microsoft
This post is based on the presentation I did for Porto Tech Hub 2015, Microsoft ♥ Open Source, slightly revised and augmented.
-
NHibernate Pitfalls: Sharing a Session in Multiple Threads
The NHibernate ISession is not thread-safe, that is, it shouldn’t be shared by multiple threads. The ISessionFactory, however, is thread-safe, and thus it should be used to create ISession instances as needed. Do not worry, creating sessions does not mean that connections to the database are immediately open and kept alive, the ISession implementation only opens database connections when they are necessary and closes them when they cease to be.
-
Lesser-Known NHibernate Features: Statistics
NHibernate makes available a number of statistics about its work; this includes, among others:
-
SharePoint Reference Document Updated
Updated on June 6th.
-
Lesser-Known NHibernate Features: Dynamic Components
NHibernate, unlike others, has lots of ways to map columns from the database to and from classes. Normally, there is a 1:1 relation between columns and properties, but it doesn’t have to be so: there are, for example, components and dynamic components.
-
Windows Live Writer Tricks
As many others, I use Windows Live Writer (WLW) as my main tool for blogging. It has aged a bit over the years and sometimes crashes, but I think it is still the best tool around for this purpose. It will only get better if Scott Hanselman (@shanselman) succeeds in releasing it as open source!
-
ASP.NET Formatted String Control
Back to ASP.NET Web Forms land! SharePoint includes a handy control, FormattedString, that can be used to render the contents of its child controls as specified in a format string; pretty much what String.Format does. I wanted to do the same with plain old ASP.NET Web Forms, and here’s what I came up with:
-
Porto Tech Hub 2015 – Wrap Up
Porto Tech Hub is over… for now! I was interesting, I got the chance to listen to some good presentations, learn a bit, and see old friends. I really liked the presentations by my former colleagues @ CRITICAL Software, Norberto Leite (@nleite), from MongoDB and Rui Ferreira, from Facebook, and, of course, the one from my friend and colleague João Esteves, which you can grab from the event’s site.
-
Porto Tech Hub 2015
-
Free Training Materials for Development
A random list that will grow, eventually, with time.
-
Packt Publishing Free Learning Library
-
Entity Framework Multitenancy Part 2 – Conventions
In my last post, I talked about different scenarios for achieving multitenancy with Entity Framework contexts. This time, I am going to show how to use conventions, wrapping the code I provided then.
-
Entity Framework Multitenancy
Update: see part two here
-
Lesser-Known NHibernate Features: Calculated Properties
With NHibernate you can have entity properties that are the result of a SQL expression (unlike other O/RMs). It is also possible to add arbitrary SQL restrictions to collections of an entity.
-
Lesser-Known NHibernate Features: Filters
Unlike other OR/Ms – which, as always, shall remain unnamed – NHibernate offers a couple of ways to automatic filter results. Basically, we have two options:
-
Defining ASP.NET Update Panel Template Contents Dynamically
The ASP.NET UpdatePanel was introduced with the ASP.NET 2.0 AJAX Extensions almost a century ago (kidding, but almost feels like it!). It allows us to have AJAX-style effects (partial page loads) with very little effort.
-
Lesser-Known NHibernate Features: Mapping By Convention
Did you know that NHibernate, like other O/RMs out there, allows you to map classes by convention? Yes, it’s true… Let me show you how!
-
Adding Custom Validation Messages in Silverlight
Sometimes it is useful to add our own validation messages to a Silverlight control, normally because we are doing custom validation through code, not through the reguar IDataErrorInfo, INotifyDataErrorInfo or ValidationAttributes. This is not straightforward, but it is possible. An example might be:
-
Silverlight Transform Markup Extension
Did you ever have one of those situations where you need to apply a data source to a control, but also convert the each of the data source elements?<ComboBox ItemsSource="{Binding ItemsSource, ElementName=MyDataSource}, Converter={StaticResource MyConverter}}" Width="100" Height="30"/><ComboBox ItemsSource="{Binding ItemsSource, ElementName=MyDataSource}, Converter={StaticResource MyConverter}}" Width="100" Height="30"/>
Normally we set the data source to the DataContext or ItemsSource property and add an item template where we specify the converter, but sometimes this can’t be done this way, for one reason or the other. So, I worked out a simple solution: the TransformedItemSource! What it does is, it allows us to specify a converter for each of the source values in the data source collection, not the data source as a whole.
-
Comunidades Portuguesas de Desenvolvimento
(This post is in Portuguese only)
-
Lesser-Known NHibernate Features: LINQ Extensions
With NHibernate, you are not bound by the out-of-the box methods that LINQ provides, and their default translations to SQL. I already mentioned that you can add your own extension methods, with minimum work:
-
Day Against DRM 2015 Campaign
For those who don't know, today is the International Day Against DRM!
-
Silverlight Method Data Source Markup Extension
A quick way to obtain a data source from a method through a markup extension, without any code:
-
Lesser-Known NHibernate Features: Serializing Configuration
This isn't exactly a feature of NHibernate, but it is something that you can do with it and most people isn't aware of.
-
Silverlight Resource Markup Extension
In case you want to use resources in your Silverlight applications, you have a couple of options. My favorite, however, is using a markup extension and RESX resource files. With this approach, you can have code such as:
-
SharePoint Filter Web Part
SharePoint includes a couple of useful web parts that can be used to filter other web parts. The problem is, they are only available in the Enterprise edition. It is easy, however, to build our own filters.
-
SharePoint Reference Document
I updated the reference document for SharePoint that I first mentioned in a previous post.
-
Silverlight DynamicResource Markup Extension
This will be my first post on Silverlight!
-
MVP Showcase 2015 – Wrap Up
(This post is in portuguese and english)
-
MVP Showcase 2015
UPDATE: you can find the slide deck here.
-
Lesser-Known NHibernate Features: Custom Loggers
Extensible as it is, it's no wonder that NHibernate also supports injecting custom loggers. The support is twofold:
-
SharePoint XSLT Web Part
After my previous post on XSLT processing, what else could follow? Of course, an XSLT web part for SharePoint!
-
XSLT Processing in .NET
God only knows why, but the .NET framework only includes support for XSLT 1.0. This makes it difficult, but not impossible, to use the more recent 2.0 version: a number of external libraries exist that can help us achieve that.
-
MVP Showcase Portugal 2015
(Portuguese only, sorry!)
-
Lesser-Known NHibernate Features: Mapping By Attributes
Some O/RMs do their mapping based on attributes. LINQ to SQL and Entity Framework are good examples, although Entity Framework also supports mapping by code. I'm not saying this is good or bad - some people think it "pollutes" POCOs, other think it makes them easier to understand -, but, likewise, NHibernate also allows to map entities by attributes, let's see how.
-
Visual Studio Tips 2
Update: third post is here.
-
Querying SharePoint
SharePoint, being a content management system, of course, offers a couple of ways to query its contents programmatically. Here we will explore some of these options.
-
ASP.NET Web Forms Extensibility: Model Binding Value Providers
ASP.NET 4.5 introduced model binding: basically, it is a way for databound controls - Repeater, GridView, ListView, etc - to be fed, not from a datasource control - ObjectDataSource, EntityDataSource, SqlDataSource, etc -, but from a method in the page. This method needs to return a collection, and may have parameters. The problem is: how these parameters get their values? The answer is: through a model binding value provider.
-
Visual Studio Tips
Update: second post here, third here, fourth here and fifth here.
-
Java vs C# – Part 2
Updated on 2018-11-09
-
Entity Framework Code First Succinctly, Second Edition
-
Hosting HTTP Resources
How do I host thee? Let me count the ways!
-
Entity Framework Extensibility Index
Updated on March 10th.
-
Freetext Extension in Entity Framework Code First
I posted before a solution for adding custom SQL functions to Entity Framework Code First as extension methods. This time I am going to show how we can do something similar for the FREETEXT function of SQL Server. Please note that this example will only work if you have the Fulltext Search component installed and your table is indexed.
-
ASP.NET Web Forms Extensibility: Control Builder Interceptors
After my previous post on Control Builders, what could possibly come next? Of course, Control Builder Interceptors! Not much documentation on this one, which is a shame, because it is an even more powerful feature that was recently introduced in ASP.NET 4.5.
-
ASP.NET Web Forms Extensibility: Control Builders
One of the most often ignored extensibility point in Web Forms is the Control Builder. Control Builders are subclasses of ControlBuilder (or other more specialized, such as FileLevelPageControlBuilder, for pages, or FileLevelMasterPageControlBuilder, for master pages) that can be specified per class. It controls some aspects of a control instance:
-
Java vs C# – Part 1
Disclaimer: long post!
-
Lesser-Known NHibernate Features: Versioning and Optimistic Concurrency
NHibernate supports the notion of entity version. An entity version is the value of some entity property that is mapped as versioned. There are several strategies for versioning:
-
Learning Microsoft Azure Review
-
Unity, Part 10: Custom Build Strategies
We’re getting there! This time, custom build strategies, or how you can tell Unity to build/act upon built objects in different ways.
-
Lesser-Known NHibernate Features: Filtering an Unloaded Collection
Suppose you have an entity with a collection of other entities (one to many, many to many); this collection is normally represented by some property implementing IEnumerable<T>, or one some more specific interface.
-
Entity Framework Pitfalls: Command Interceptors and Identity Keys
The IDbCommandInterceptor (sorry, no official documentation) interface was introduced in Entity Framework 6 as part of the new interception and logging API, and allows the interception of the SQL and its parameters that are sent to the database as the result of DbContext CRUD operations.
-
SQL Server Auditing
Probably the best mechanism for auditing changes to tables in SQL Server is Change Data Capture, which I already covered here. Unfortunately, it only works with the Enterprise editions of SQL Server, something that not everyone has access to.
-
Custom Entity Framework Code First Convention for Discriminator Values
Since version 6, Entity Framework Code First allows the injection of custom conventions. These conventions define rules that will be applied by default to all mapped entities and properties, unless explicitly changed.
-
Entity Framework Pitfalls: Mapping Discriminator Columns
When you use a discriminator column, that is, a column that holds a value that tells Entity Framework what type the row refers to, or what restriction it shall use when querying the entity, you cannot map this column as a property in your entity.
-
Lesser-Known NHibernate Features: Result Transformers
A result transformer, in NHibernate, is some class that implements the IResultTransformer interface:
-
Getting the SQL for HQL and Criteria Queries
OK, so, I already showed how we can get the SQL that was generated from a LINQ query. Of course, we can do the same for both HQL and Criteria APIs as well (QueryOver is just a wrapper around Criteria, mind you).
-
Adding Support for ISupportInitialize in NHibernate
The .NET ISupportInitialize interface is used when we want to support staged initialization for objects. Its BeginInit method is called when initialization is about to start and EndInit when it is finished.
-
Lesser-Known NHibernate Features – Generating Database Scripts
As you may know, NHibernate knows how to generate the database for you from its model. Any of the supported databases will do.
-
Unity, Part 9: Integration With Managed Extensibility Framework
This time, I will be talking about integrating Unity with Managed Extensibility Framework (MEF). You can find the other posts in the series here (how to use Unity in a web application), here (adding Interfaces), here (registration by convention), here (injecting values), here (extensions), here (aspect-oriented programming), here (dependency injection) and the first one here (introduction).
-
ASP.NET Web Forms Prompt Validator
For those still using Web Forms and Microsoft’s validation framework, like yours truly - and I know you’re out there! -, it is very easy to implement custom validation by leveraging the CustomValidator control. It allows us to specify both a client-side validation JavaScript function and a server-side validation event handler.
-
NHibernate Pitfalls: Versioned Entities Are Not Batcheable
This is part of a series of posts about NHibernate Pitfalls. See the entire collection here.
-
My MVP Blog
I started cross posting to my MVP blog, but you can continue following just this one because it will always be updated.
-
Generating GDI+ Images for the Web
.NET’s Graphics Device Interface (GDI+) is Microsoft’s .NET wrapper around the native Win32 graphics API. It is used in Windows desktop applications to generate and manipulate images and graphical contexts, like those of Windows controls. It works through a set of operations like DrawString, DrawRectangle, etc, exposed by a Graphics instance, representing a graphical context and it is well known by advanced component developers. Alas, it is rarely used in web applications, because these mainly consist of HTML, but it is possible to use them. Let’s see how.