Dustin Horne

Developing for fun...

Scripting Migrations in EF Core

Intro

Sometimes it's useful to generate T-SQL scripts for our Entity Framework Code First Migrations.  Creating and applying migrations to our local development database(s), whether using LocalDb or something else, are fairly trivial tasks.  What isn't as intuitive is how we can generate scripts from these migrations.  Let's explore how this can be accomplished.

More...

Many to Many Relationships in Entity Framework 7

Note:  The information in this post is way outdated.  For a more in depth started on EF Core and different relationship mappings please refer to my updated Deeper Dive Into EF Core post.

In the coming days I'll be introducing a new series of posts about working with MVC 6 and WebAPI in ASP .NET 5.  This will include demonstrations using Entity Framework 7 as I dive into it.  In the meantime, though, I wanted to demonstrate something that functions differently in EF 7 than in previous iterations: Many-to-Many relationships. More...

Generic Attributes in C#

First I'd like to note a correction as this original post was unintentionally misleading.  The following works with Mono but will not work with the full fledged .NET Framework.

This afternoon while doing some related research I realized that I had been doing something for awhile that appears to be somewhat of a unicorn in the C# community:  using generic attributes.  Upon further research I saw a lot of information on creating generic attributes that ranged from "you can't" to "here's how you create a custom type descriptor and dynamically inject the attribute".  As I have been doing it for awhile a much easier way, I somehow was never aware that it was a problem for some, so here is how you do it.

More...

Sending Email With Google Mail and ASP.NET

If you're using Google Apps for your email you may want to send email through a Google Apps account from your website.  This is a process I've found to be poorly documented (the documentation can be difficult to find) and there are several examples of different implementations, some of which work and some do not.  You need to make sure you're using the correct outbound server, the correct port, and setting up the authentication credentials properly.  Here I'm going to show you how to make it work. More...

Consuming RSS Cross-Domain in jQuery and MVC

AJAX is a powerful tool for making asynchronous requests from the client.  Unfortunately, this is often limited to same domain requests due to security restrictions put in place to prevent cross site scripting.  This also makes it difficult to consume external data such as RSS feeds if a security policy hasn't been put in place to allow cross domain callers with javascript.  In these cases it's necessary to use your server to proxy the data back to your page. More...

Simple Asset Manager for MVC

Lately I've been using a lot of jQuery and other custom javascript in my projects.  I like to use external CDNs when possible to load my script files.  In particular, I like to use the asp.net CDN for use with jQuery.  For much of this work I can simply put my script references in the layout pages, however there are times when I want specific scripts for specific pages.  There are also times when I want to be able to upgrade a script to a newer version.  This may require modifying multiple views.  Additionally, it would require modifying my HTML/Razor for at least my layout view and re-uploading it to the server. More...

AJAX File Uploads with jQuery and MVC 3

Recently I was working on a project that required upload of images.  I wanted to upload the images AJAX style without refreshing the page and thought jQuery would be a good fit.  Using jQuery to post standard forms is extremely simple, but when posting multi-part forms for uploading files it's not so intuitive.  This is due to browser security restrictions and sandboxing.  Today I'm going to show you how to fake an asynchronous upload without reloading the page and get a result back from the server. More...

Dynamic Custom Error Pages in ASP.NET MVC 2

Recently, I had to implement a dynamic custom 404 error page in an ASP.NET MVC2 website.  My first instinct was to turn CustomErrors mode on and setup a 404 Error, but this failed to return my custom error page in a shared hosting environment and instead displayed the default IIS 404 page.  I'll walk you through fixing this in just a minute, but for now I want to show you how to create the custom 404 page. More...