Monday, December 17, 2012

Converting Enum to List in C#

This is an easy but recurrent question that I end searching on Google from time to time. So to adhere to this blog's motto and not searching it again here's the solution:

Enum.GetValues(typeof(SomeEnum)).Cast();

(The original solution thread at stackoverflow)

Tuesday, December 4, 2012

NCalc: a mathematical expressions evaluator in .NET


For a project that I've been developing lately I needed to evaluate some mathematical expressions that I'll store as text strings. So my first thought was like "I'm not the first man on earth with such necessity, ergo, it must have been accomplished by someone else before me". That is a thought that I have in a lot of situations, but fortunately this time it turned out to be truth.

As the CodePlex project's page states: "NCalc is a mathematical expressions evaluator in .NET. NCalc can parse any expression and evaluate the result, including static or dynamic parameters and custom functions".

IMHO is an excellent tool, but to be fair, I'm not doing nothing overly complicated in my project.

Thursday, November 29, 2012

HOWTO trigger MVC 3 validation from jQuery


Have you ever wonder how to trigger de MVC 3 form validations from jQuery? ... well, I've done it, and belive me, I spend more than an hour finding out how to. So, the answer is pretty simple: to trigger the validators do something like
$('#MyForm').validate().form();
And for checking if the all the validations get passed look for something like
var isMyFormValid = $('#MyForm').validate().valid();
That's all.

(The answer was found thanks to the ASP.NET forums)

Monday, November 26, 2012

Test your javascript code online


Some time ago thanks to an answer at StackOverflow I discovered an amazing web service called jsfiddle. Basically it allows you to test your JavaScript code online with the option to make use of some of the most popular frameworks out there (like jQuery, Mootools, YUI, Dojo, etc..), and if you need so, you can share your "fiddles" too.

An excellent tool that always come handy.

Friday, November 23, 2012

Thursday, November 22, 2012

Brief introduction to MVC 3 partial views

Here's a brief and to the point introduction to MVC 3 partial views by Microsoft's Rachel Appel:

http://rachelappel.com/razor/partial-views-in-asp-net-mvc-3-w-the-razor-view-engine/

The introduction covers in less than 10 minutes the following topics:

  • What is a partial view and when should I use it?
  • Rendering partial views
  • Creating a partial view
  • Sharing Data between views and partial views

Wednesday, November 21, 2012

HOW TO: embed MVC 3 Razor code inside a javascript block

This one is actually a kind of weird trick that's is required (as far as I know) in the current version of MVC for embedding razor code inside a javascript block. It's very possible that you find yourself wondering how to accomplish this when you are begining with MVC and razor:

http://stackoverflow.com/questions/4204669/asp-net-mvc3-rc-razor-views-syntax-for-embedding-code-inside-javascript-bloc

P.S. I'm not sure if this is still necessary in the current version of MVC (MVC 4 ath the time of this writing)...

Monday, November 19, 2012

HOW TO: query many-to-many relations in EF 4


While working with Entity Framework I found my self a bit lost while working with many-to-many relations, as I expect that a class should exist to represent the many-to-many relation table, but in fact, it doesn't exist. So how on earth do you make a query that intends to use the many-to-many relation?...

The answer come from the usual suspect, her's the link at StackOverflow:

http://stackoverflow.com/questions/553918/entity-framework-and-many-to-many-queries-unusable

Monday, September 24, 2012

Cascading dropdown lists with jQuery

Here is a [1]GitHub link to a small jQuery plug-in that helps to make <select> HTML elements to refresh their content from a JSON source in response to the 'change' event of another <select> element.

The code is based on this Stack Overflow thread: http://stackoverflow.com/questions/4458970/cascading-drop-downs-in-mvc-3-razor-view.



[1]https://github.com/manuelnavarroc/jquery.cascade-select

Thursday, September 20, 2012

So .NET MVC is Open Source? ... yes, it is!

Recently I had a doubt about the insides of a .NET MVC method, so I posted a question on SO. To my surprise, one of the answers told me to take a look at the source code by myself... and then I met The Source Code:

http://aspnetwebstack.codeplex.com/SourceControl/list/changesets

A highly recommended resource for every MVC programmer out there.

Wednesday, July 18, 2012

HOW TO: take ownership of your local SQL Server 2008 Express

So, you have administrator privileges on your machine but you don't have ownership over your SQL Server 2008 Express instance. How can this even be possible? ... actually is quiet simple, you just have to create your SQL Server 2008 Express instance with a different user to the one with which you are logged in, that's all, sad and simple.


One excellent script solution here: http://archive.msdn.microsoft.com/addselftosqlsysadmin/

NOTE: if you happen to have a non-English windows version (as I do), you will have to modify the script, since it relays on command outputs that are language dependant.

Thursday, May 10, 2012

Oracle SQL Developer FK References

Yesterday I needed to find what tables were referencing a particular table in Oracle. These days I'm working with Oracle SQL Developer, and being a guy used to MS SQL Server Tools, I thought that the option should be somewhere in the GUI, but to my surprise there wasn't any such option. Thankfully the solution was just a google-search away.

In this thread at stackoverflow user junaling explains how to add the functionality to Oracle SQL Developer:

http://stackoverflow.com/a/8230251/1299317

Maybe it's worth to mention that the result of adding the user defined extension to Oracle SQL Developer is that you will see a new tab named FK References in the table information window (the one that you see whenever you click on a table on the Connections window).

Tuesday, April 24, 2012

HOW TO: Map an entity property to a CLOB field (nHibernate / Fluent)

I'm working on a project that uses nHibernate with Fluent. Today I needed to map an entity property to an Oracle CLOB field. So, after a little of googling, I find that the solution is just to set the CustomSqlType property of the entity to "CLOB" in the mapping class, or if you prefer (as in my case) in a Convention.

The link to the solution in Stackoverflow.

Friday, April 13, 2012

HTTPS on WCF Web service & Temporary Certificates for Use During Development

Many times I find myself searching the same technical stuff over and over, so, in an heroic effort towards efficiency I decide to start this blog. The idea is that every technical research that I have to go through will be documented here, so whenever I need the information again, it will be easy to reach and remember. BTW as in my gaming blog, I want to remark that English is not my mother language, so this blog will be an exercise too. Suggestions and corrections are welcome.

Well, enough blathering, let's begin with the tech stuff...

Yesterday I needed to secure a windows service that exposes a Web service through WCF wsHttpBinding. While searching how to accomplish the task, I realize that I have searched a lot of times about how in earth do the SSL certificates works, and how do you create a temporary certificate for development purposes. So here are the links to the omnipotent Microsoft reference:

Bonus:

Trough the day I searched for a couple of useful things too. Maybe they look pretty basic but I'm sure I'll look for them in the future: