Skip to content

Instantly share code, notes, and snippets.

View schotime's full-sized avatar

Adam Schroder schotime

  • Melbourne, Australia
View GitHub Profile
var collection = new MongoCollection(tranny.TypeName, DB, DB.CurrentConnection);
var result = collection.Find(fly, tranny.Take, tranny.Skip);
// So that
IEnumberable<T> list = (IEnumerable<T>)result;
// Where T is the type is in the list
//Take this
public ActionResult Logins()
{
var mapped = _repository
.Query(new GetLoginHistoryAndUser())
.AutoMap<LoginHistory, LoginHistoryDisplay>()
.ToList();
return View(new LoginHistoryViewModel { LoginHistory = mapped });
//Mappings
CreateMap<DateTime, FormattedDateTime>().ConvertUsing<FormattedDateConverter>();
CreateMap<string, bool>().ConvertUsing(x => x == "Y" || x.ToLowerInvariant() == "on" || x == "1");
//Dictionary
var dict = new Dictionary<string,object>() { { "id", 2 },{ "date", DateTime.Now }, { "istrue", "Y" } };
//Class
public class AutoMapperProfile : Profile
{
protected override void Configure()
{
CreateMap<DateTime, FormattedDateTime>().ConvertUsing<FormattedDateConverter>();
CreateMap<string, bool>().ConvertUsing(x => x == "Y" || x.ToLowerInvariant() == "on" || x == "1");
DictionaryToClassConverter.ConvertFromDictionary(this, GetType().Assembly, x => x.ToLowerInvariant());
}
public class RepositoryConvention : IRegistrationConvention
{
public void Process(Type type, StructureMap.Configuration.DSL.Registry registry)
{
if (type.IsClass && type.GetInterfaces().Where(x => x == typeof(IRepository)).Any())
{
if (type.Name.Contains(GlobalSettings.DbType))
{
Type specificInterface = type.GetInterfaces().Where(x => x != typeof(IRepository)).First();
registry.For(specificInterface).Use(type);
@schotime
schotime / gist:925273
Created April 18, 2011 12:56
QueryInvoker
public interface IQueryInvoker
{
TViewModel Invoke<TViewModel>() where TViewModel : new();
}
public class QueryInvoker : IQueryInvoker
{
private readonly IObjectResolver _objectResolver;
public QueryInvoker(IObjectResolver objectResolver)
@schotime
schotime / gist:961304
Created May 8, 2011 11:02
glimpse workaround
var sql = "!" + application.Server.HtmlEncode(item.Sql).Replace("] ", "&#93; ") + "!"; //Glimpse Sanitizer workaround
@schotime
schotime / gist:966339
Created May 11, 2011 12:03
Example petapoco use
public class Security
{
public int SecurityId { get; set; }
public string Name { get; set; }
}
public class User
{
public int UserId { get; set; }
public string FirstName { get; set; }
@schotime
schotime / gist:977737
Created May 18, 2011 00:13
PetaPoco StructureMap
//This is how I use PetaPoco with structure map but I'm also using the IDatabase interface from my branch at http://github.com/schotime/petapoco
public class PetaPocoRegistry : Registry
{
public PetaPocoRegistry()
{
Scan(x =>
{
x.TheCallingAssembly();
x.WithDefaultConventions();
@schotime
schotime / gist:990150
Created May 25, 2011 01:31
Petapoco Dbparameter
_databaseQuery.Execute("insert into temp1 (t) values (@0)"
, new SqlParameter() { SqlDbType = SqlDbType.VarBinary, Value = new byte[] {12, 1, 34, 234}});