Skip to content

Instantly share code, notes, and snippets.

@gscattolin
gscattolin / new_gist_file
Created September 10, 2013 18:31
Drop a Table
use DataBaseName
go
EXEC sp_MSforeachtable @command1 = "DROP TABLE ?"
go
@gscattolin
gscattolin / new_gist_file
Created September 10, 2013 18:30
Insert special values (Guid, Time)
use ProjectCode
insert into dbo.BlogPosts values(newid(),'Post1','Content1',CURRENT_TIMESTAMP,'F26D2321-FE49-472D-AE80-0FDECF0BF6BC')
go
insert into prices (group, id, price)
select
7, articleId, 1.50
from article where name like 'ABC%';
@gscattolin
gscattolin / new_gist_file
Created September 10, 2013 18:29
see properties of a table
EXEC sp_help TableName;
@gscattolin
gscattolin / new_gist_file
Created September 10, 2013 18:28
Access to SQL and add admin rights
shut down SQL Server from services
open cmd window (as admin) and run single-user mode as local admin with this command
c:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\Binn\sqlservr.exe" -m -s SQLEXPRESS
open another cmd window (as admin)
open sqlcmd
@gscattolin
gscattolin / new_gist_file
Created September 10, 2013 18:27
Create Session factory in Fluent NHibernate
private static ISessionFactory CreateSessionFactory()
{
//const string Connstring = "server=SWIGVA01-SRV341;database=LeafPoint_Global;" +
// "User Id=lp_global;Password=lp_gl0b4l;";
const string Connstring = @"server=.\SQLEXPRESS;database=SimpleDB;" +
"Integrated Security=SSPI;";
return Fluently.Configure()
.Database(MsSqlConfiguration
@gscattolin
gscattolin / new_gist_file
Created September 10, 2013 18:27
Create DB Nhibernate
const string Connstring = "server=SWIGVA01-SRV341;database=LeafPoint_Global;" +
"User Id=user;Password=pwd;";
configuration= Fluently.Configure()
.Database(MsSqlConfiguration
.MsSql2008
.ConnectionString(Connstring).ShowSql())
.Mappings(m => m.FluentMappings
.AddFromAssemblyOf<FunctionMap>()
//.Conventions.Add(new PrimaryKeyNameConvention())
@gscattolin
gscattolin / new_gist_file
Created September 10, 2013 18:25
Fluent NHibernate Get Info on Tables
var metadata = sf.GetAllClassMetadata().ToList();
IDictionary<string,IClassMetadata> data = sf.GetAllClassMetadata();
//Dictionary<string, SingleTableEntityPersister> lstTable = sf.GetAllClassMetadata().ToDictionary(x => x.Key, x=> x.Value);
foreach (var table in metadata)
{
Console.WriteLine("List {0}", table.ToString());
}
foreach(KeyValuePair<string,IClassMetadata> entry in data)
{
Console.WriteLine("Value {0} {1}",entry.Key,entry.Value.EntityName);
@gscattolin
gscattolin / new_gist_file
Created September 10, 2013 18:24
Deep copy, clone, ICloneable
// Shows how to return a deep copy clone of an object.
class CloneTest : ICloneable
{
public int SomeProperty { get; set; }
public object Clone()
{
CloneTest clone = new CloneTest();
clone.SomeProperty = this.SomeProperty;
@gscattolin
gscattolin / new_gist_file
Created September 10, 2013 18:21
Get Assembly path
/// <summary>
/// Returns the path (with ending backslash) of current executing assembly
/// </summary>
/// <returns>Path of executing assembly</returns>
public static string AssemblyPath () {
return Path.GetDirectoryName (Assembly.GetExecutingAssembly ().Location) +
Path.DirectorySeparatorChar;
}
/// <summary>
@gscattolin
gscattolin / new_gist_file
Created September 10, 2013 18:20
Delete files in a folder/folder
private void ClearFolder(string FolderName)
{
DirectoryInfo dir = new DirectoryInfo(FolderName);
foreach (FileInfo fi in dir.GetFiles())
{
fi.IsReadOnly = false;
fi.Delete();
}