Skip to content

Instantly share code, notes, and snippets.

View gamlerhart's full-sized avatar

Roman Stoffel gamlerhart

View GitHub Profile
@gamlerhart
gamlerhart / AddingFieldsEtc.cs
Created April 6, 2011 19:32
CreateAssembly.cs
// Creating a field on the type
FieldBuilder field = typeBuilder.DefineField("nameOfField", typeof (string), FieldAttributes.Private);
// Adding a new property to the type
PropertyBuilder property = typeBuilder.DefineProperty("NameOfProperty",
PropertyAttributes.HasDefault,
typeof (string), null);
// A property needs the actual implementation-method. Here the a getter
MethodBuilder getterMethod = typeBuilder.DefineMethod("get_NameOfProperty",
@gamlerhart
gamlerhart / ContextCreatedByDriver.cs
Created April 6, 2011 19:58
ContextCreatedByYourDriver.cs
class ContextCreatedByDriver{
public IQueryable<TheType> TheType
{
get{/* your implementation */}
}
}
public interface ComplexEventHandler {
void ohMyGod(String name,String otherName, int test);
}
public static class Db4oExtensions
{
public static void InTransaction(this IObjectContainer container,
Action<IObjectContainer> txClosure )
{
InTransaction(container, c =>
{
txClosure(c);
return true;
});
@gamlerhart
gamlerhart / DeleteDocument.cs
Created June 23, 2011 19:39
RavenDB-Blog-Post
using (var session = documentStore.OpenSession())
{
var person = (from p in session.Query<Person>()
where p.SirName == "Stoffel"
select p).First();
session.Delete(person);
session.SaveChanges();
}
@gamlerhart
gamlerhart / BachLoad.cs
Created June 29, 2011 20:18
RavenDB-Documents
var order = session.Query<Order>()
.Customize(x => x.Include<Order>(o=>o.CustomerId)) // Load also the costumer
.First();
var customer = session.Load<Customer>(order.CustomerId);
@gamlerhart
gamlerhart / QueryNoStale.cs
Created July 12, 2011 18:19
RavenDB-Query
// Include all changes since the last 'SavenChanges'
var johns = (from c in session.Query<Customer>()
.Customize(q => q.WaitForNonStaleResultsAsOfLastWrite())
where c.Name == "John"
select c).Take(5);
@gamlerhart
gamlerhart / DomainModel.cs
Created July 22, 2011 12:17
RavenSafeByDefault
public class BlogPost
{
public BlogPost(string title)
{
Title = title;
}
public string Id { get; set; }
public string Title { get; set; }
public string Content { get; set; }
@gamlerhart
gamlerhart / GetRightsForAPort.cs
Created August 3, 2011 18:26
EmbeddedRavenDB
NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(8080);
@gamlerhart
gamlerhart / BlogPost.cs
Created August 26, 2011 13:27
RavenDB-Attachments
public class BlogPost
{
public BlogPost(string title)
{
Title = title;
}
public string Id { get; set; }
public string Title { get; set; }
public byte[] Picture { get; set; }