Skip to content

Instantly share code, notes, and snippets.

View davybrion's full-sized avatar

Davy Brion davybrion

  • That Extra Mile
  • Belgium
View GitHub Profile
@davybrion
davybrion / hql_example.cs
Created April 24, 2011 15:57
NHibernate QueryOver projection into DTO... anyone know of a cleaner way?
var orderHeaders = Session.CreateQuery(
@"select new OrderHeader(o.OrderedOn, c.Name, e.FirstName || ' ' || e.LastName)
from Order o inner join o.Customer c inner join o.Employee e")
.List<OrderHeader>();
@davybrion
davybrion / gist:2725488
Created May 18, 2012 14:16
is it alright to use this in a PRG scenario in asp.net mvc? or totally not done?
public class SetTempDataWhenModelStateInvalidAttribute : ActionFilterAttribute
{
public override void OnActionExecuted(ActionExecutedContext filterContext)
{
base.OnActionExecuted(filterContext);
if (!filterContext.Controller.ViewData.ModelState.IsValid)
{
filterContext.Controller.TempData["ModelState"] = filterContext.Controller.ViewData.ModelState;
}
}
@davybrion
davybrion / s1.js
Created September 3, 2012 16:40
code snippets for "Repeated Failed Log-Ins: What's Your Strategy?" post
function delayAuthenticationResponse(session, callback) {
if (!session.attempts) {
session.attempts = 1;
} else {
session.attempts++;
}
setTimeout(callback, session.attempts * 1000);
}
@davybrion
davybrion / s1.cs
Created September 3, 2012 17:21
code snippets for "Implementing a Value Object" post
public class Address
{
public Address(string street, string city, string region,
string postalCode, string country, string phoneNumber)
{
_street = StringValueOrEmptyString(street);
_city = StringValueOrEmptyString(city);
_region = StringValueOrEmptyString(region);
_postalCode = StringValueOrEmptyString(postalCode);
_country = StringValueOrEmptyString(country);
@davybrion
davybrion / s1.cs
Created September 3, 2012 17:43
code snippets for "Introduction To Dependency Injection" post
public class SqlMetaDataProvider : IMetaDataProvider
{
private readonly string _connectionString;
private readonly SqlDataRetriever _sqlDataRetriever;
public SqlMetaDataProvider(string connectionString)
{
_connectionString = connectionString;
_sqlDataRetriever = new SqlDataRetriever();
}
@davybrion
davybrion / s1.xml
Created September 3, 2012 17:59
code snippet for "Native ID Generation With NHibernate" post
<id name="Id" column="CustomerId" type="long" unsaved-value="-1" access="field.camelcase-underscore">
<generator class="native" >
<param name="sequence">sq_customer</param>
</generator>
</id>
@davybrion
davybrion / s1.xml
Created September 3, 2012 18:02
code snippet for "Read Only Data With NHibernate" post
<class name="Foo" table="foo_table" mutable="false">
@davybrion
davybrion / s1.cs
Created September 3, 2012 18:14
code snippets for "Sending NHibernate Entities Over The WCF Wire" post
[ServiceContract]
public interface ICustomerService
{
[UseNetDataContractSerializer]
[OperationContract]
IList<Customer> GetCustomersWithTheirOrders();
[UseNetDataContractSerializer]
[OperationContract]
void PersistCustomer(Customer customer);
@davybrion
davybrion / s1.c
Created September 3, 2012 18:20
code snippets for "Creating Remote TCP/IP Printer Ports From Code" post
BOOL WINAPI XcvData(HANDLE hXcv, LPCWSTR pszDataName, PBYTE pInputData, DWORD cbInputData,
PBYTE pOutputData, DWORD cbOutputData, PDWORD pcbOutputNeeded, PDWORD pdwStatus);
@davybrion
davybrion / s1.cs
Created September 3, 2012 18:25
code snippet for "Encapsulating Collections" post
public class Member
{
private readonly List<Member> _parents;
private readonly List<Member> _children;
public Member()
{
_parents = new List<Member>();
_children = new List<Member>();
}