Skip to content

Instantly share code, notes, and snippets.

@johnmmoss
johnmmoss / gist:850efa4b32c3b9782d5c
Created March 31, 2015 07:08
Enitity Framework 6 Setting up Data
context.Departments.Add(new Department() { Id = 1, Name = "Department 1" });
context.Departments.Add(new Department() { Id = 2, Name = "Department 2" });
context.Employees.Add(new Employee() { Id = 1, ForeName = "John" });
context.Employees.Add(new Employee() { Id = 2, ForeName = "Mark" });
context.Employees.Add(new Employee() { Id = 3, ForeName = "Mat" });
@johnmmoss
johnmmoss / gist:2b79345021c8c74b532c
Created March 31, 2015 07:13
Entity Framework 6 TestDbSet
public class TestDbSet<TEntity> : DbSet<TEntity>, IQueryable, IEnumerable<TEntity>, IDbAsyncEnumerable<TEntity>
where TEntity : class
{
ObservableCollection<TEntity> _data;
IQueryable _query;
public TestDbSet()
{
_data = new ObservableCollection<TEntity>();
_query = _data.AsQueryable();
@johnmmoss
johnmmoss / gist:cc0777ab1acc8ac265f0
Created April 2, 2015 20:11
Web.config log4net settings
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<!-- more config -->
<log4net configSource="log4net.config" />
@johnmmoss
johnmmoss / gist:7c021ab6ba4ac33e82d7
Last active March 26, 2016 10:40
log4net file sample config
<?xml version="1.0" encoding="utf-8"?>
<log4net>
<!-- Log to vs output window -->
<appender name="TraceAppender" type="log4net.Appender.TraceAppender" >
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%timestamp [%level] %-60message %newline" />
</layout>
</appender>
@johnmmoss
johnmmoss / gist:d9a4d97b4c2bdd899fac
Created April 2, 2015 20:18
log4net Configure code
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
// Configure log4net
log4net.Config.XmlConfigurator.Configure();
}
}
private static readonly ILog _logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public ActionResult Index()
{
_logger.Info("Displaying the home page");
return View();
}
@johnmmoss
johnmmoss / gist:5e45b8eea27f15201ea1
Created April 7, 2015 18:58
PowerShell SQL path
$server = "localhost";
$instance = "Default";
$database = "timesheets";
$path = "sqlserver:\sql\$server\$instance\databases\$database\tables";
@johnmmoss
johnmmoss / gist:8b7c32be6d8f7ab04093
Created April 7, 2015 19:01
PowerShell Sql snapins
set-executionpolicy remotesigned
add-pssnapin sqlserverprovidersnapin100
add-pssnapin sqlservercmdletsnapin100
@johnmmoss
johnmmoss / gist:f56a7bf4d1edd904fa7e
Created April 7, 2015 19:04
PowerShell execute Get-ChildItem
$tableset = get-childitem $path -ErrorAction stop
@johnmmoss
johnmmoss / gist:8fd10836fcfccba384f1
Created April 7, 2015 19:09
PowerShell for loop
foreach ($table in $tableset)
{
write-host $table.name
}