Skip to content

Instantly share code, notes, and snippets.

@SamLeach
SamLeach / Entity Framework 4 Clone
Created September 8, 2014 08:17
Entity Framework 4 Clone
// http://www.codeproject.com/Tips/474296/Clone-an-Entity-in-Entity-Framework
// Static
public static T CopyEntity<T>(MyContext ctx, T entity,
bool copyKeys = false) where T : EntityObject
{
T clone = ctx.CreateObject<T>();
PropertyInfo[] pis = entity.GetType().GetProperties();
foreach (PropertyInfo pi in pis)
@SamLeach
SamLeach / select_constaints.sql
Last active August 29, 2015 14:06
Select Oracle User Constraint by name
SELECT owner, table_name
FROM USER_CONSTRAINTS
WHERE constraint_name = 'CNTR_DTYP_FK'
@SamLeach
SamLeach / NuGet log4mongo-net
Created September 28, 2014 13:29
NuGet log4mongo-net
Install-Package log4mongo-net
@SamLeach
SamLeach / web.config.xml
Last active August 29, 2015 14:07
log4mongo log4net web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net configSource="mongo_appender.config"/>
</configuration>
@SamLeach
SamLeach / mongo_appender.config.xml
Last active August 29, 2015 14:07
log4net log4mongo config
<?xml version="1.0"?>
<log4net>
<appender name="MongoDBAppender" type="Log4Mongo.MongoDBAppender, Log4Mongo">
<connectionString value="mongodb://localhost" />
<collectionName value="logs" />
<field>
<name value="timestamp" />
<layout type="log4net.Layout.RawTimeStampLayout" />
</field>
<field>
@SamLeach
SamLeach / Logger.cs
Last active August 29, 2015 14:07
log4net log4mongo Logger wrapper
public class Logger : ILogger
{
private readonly ILog log;
public Logger(string type)
{
this.log = LogManager.GetLogger(type);
}
public void Debug(object message)
@SamLeach
SamLeach / ILogger.cs
Last active August 29, 2015 14:07
log4net log4mongo ILogger wrapper
public interface ILogger
{
void Debug(object message);
void Debug(object message, Exception exception);
void Error(object message);
void Error(object message, Exception exception);
void Fatal(object message);
void Fatal(object message, Exception exception);
@SamLeach
SamLeach / HomeController.cs
Last active August 29, 2015 14:07
HomeController log4mongo
public class HomeController : Controller
{
private readonly ILogger logger;
public HomeController(ILogger logger)
{
XmlConfigurator.Configure();
this.logger = logger;
}
@SamLeach
SamLeach / mongod_dbpath
Last active August 29, 2015 14:07
mongod dbpath
mongod -–dbpath C:\data
@SamLeach
SamLeach / mongoShellFindAll.js
Last active August 29, 2015 14:07
mongo shell find all
db.logs.find().pretty()