Skip to content

Instantly share code, notes, and snippets.

View ianfnelson's full-sized avatar

Ian Nelson ianfnelson

View GitHub Profile
@ianfnelson
ianfnelson / EF3_1.cs
Created September 18, 2014 08:34
Snippets for 2011 blog post "Entity Framework Week Part 3: Runtime Issues Encountered"
public class Order
{
public Order()
{
this.Address = new Address();
}
public virtual Address Address { get; set; }
}
@ianfnelson
ianfnelson / EF2_1.cs
Last active April 1, 2024 19:33
Snippets for 2011 blog post "Entity Framework Week Part 2: Conventions and Fluent Mappings"
public class MyAppPrimaryKeyConvention : IConfigurationConvention<PropertyInfo, PrimitivePropertyConfiguration>
{
public void Apply(PropertyInfo memberInfo, Func<PrimitivePropertyConfiguration> configuration)
{
if (memberInfo.Name == "Id")
{
// We need to avoid overriding concrete class mapped using TPH.
if (memberInfo.ReflectedType.IsSubclassOf(typeof(ProductFeature)) ||
memberInfo.ReflectedType.IsSubclassOf(typeof(ProductInsert)))
{
@ianfnelson
ianfnelson / EF1_1.cs
Created September 18, 2014 09:05
Snippets for 2011 blog post "Entity Framework Week Part 1: Introduction, Configuration and Initialization"
DbDatabase.SetInitializer<MyAppContext>(null);
@ianfnelson
ianfnelson / NHAggregates.cs
Created September 18, 2014 09:08
Snippet for 2010 blog post "NHibernate and Mapping Aggregates"
public class IdeaMap : ClassMap<Idea>
{
public IdeaMap()
{
Id(x => x.Id)
.Column("ID")
.GeneratedBy.Identity();
Map(x => x.Summary).Not.Nullable();
Map(x => x.Description).WithMaxSize().Not.Nullable();
@ianfnelson
ianfnelson / IoC_1.cs
Created September 18, 2014 12:14
Snippets for 2010 blog post "Testing IoC Registrations"
AutoMapper.Mapper.AssertConfigurationIsValid();
@ianfnelson
ianfnelson / WCFLog_1.cs
Created September 18, 2014 12:18
Snippets for 2010 blog post "WCF - Logging Before and After Operation Invocation"
using System;
using System.ServiceModel.Description;
using Castle.Core.Logging;
/// <summary>
/// Being a custom EndpointBehavior added to the WCF services such that each operation outputs
/// a debug log message before and after invocation.
/// </summary>
public class OperationLoggingEndpointBehavior : IEndpointBehavior
{
@ianfnelson
ianfnelson / WCFEH_1.cs
Created September 18, 2014 12:20
Snippets for 2010 blog post "WCF - Global Exception Handling"
using System;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using Castle.Core.Logging;
/// <summary>
/// Being a custom EndpointBehavior added to the WCF services to provide custom error handling functionality.
/// Namely, logging error so it doesn't get ignored.
/// </summary>
@ianfnelson
ianfnelson / TL1.cs
Created September 18, 2014 12:30
Snippets for 2009 blog post "Testing LINQ Queries"
/// <summary>
/// Finds leads in the repository by Customer Name.
/// </summary>
/// <param name="repo" />Repository of Leads</param>
/// <param name="customerName" />Customer name</param>
/// <returns>Leads matching the criteria</returns>
public static IQueryable<Lead> ByCustomerName(this IQueryable<Lead> repo, string customerName)
{
if (customerName.IsNullOrEmpty())
{
@ianfnelson
ianfnelson / WCFNH_1.cs
Created September 18, 2014 12:38
Snippets for 2010 blog post "WCF - NHibernate Unit Of Work Endpoint Behavior"
using System;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
/// <summary>
/// Being a custom EndpointBehavior added to the WCF services such that each operation begins a
/// new unit of work when invoked, and closes the same unit of work after invocation.
/// </summary>
/// <remarks>
/// In practice, we are using this simply to manage NHibernate sessions - opening a new Session at
@ianfnelson
ianfnelson / MVCG1.cs
Created September 18, 2014 12:56
Snippets for 2010 blog post "An MVC Gotcha and the PRG Pattern"
using System;
namespace MvcGotcha1.Models
{
public class FooModel
{
public int FooCounter { get; set; }
}
}