Created
April 17, 2012 22:40
-
-
Save WaYdotNET/2409567 to your computer and use it in GitHub Desktop.
Ruby vs C#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using FluentNHibernate.Mapping; | |
public class WebReference | |
{ | |
public virtual int Id { get; private set; } | |
public virtual string Title { get; set; } | |
public virtual string SubTitle { get; set; } | |
public virtual string ImageSmall { get; set; } | |
public virtual string ImageBig { get; set; } | |
public virtual string DescriptionSmall { get; set; } | |
public virtual string DescriptionBig { get; set; } | |
public virtual string Evidence { get; set; } | |
public virtual string Url { get; set; } | |
public virtual Template Template { get; set; } | |
// public virtual TypeOfTemplate TypeOfTemplate { get; set; } | |
} | |
public class Template | |
{ | |
public virtual int Id { get; private set; } | |
public virtual string Title { get; set; } | |
public virtual string Css { get; set; } | |
public virtual string Body { get; set; } | |
// public virtual TypeOfTemplate TypeOfTemplate { get; set; } | |
} | |
public class TemplateArticle : Template | |
{ | |
} | |
public class WebReferenceMap : ClassMap<WebReference> | |
{ | |
public WebReferenceMap() | |
{ | |
Id(m => m.Id); | |
Map(m => m.Title).Not.Nullable(); | |
Map(m => m.SubTitle); | |
Map(m => m.ImageSmall); | |
Map(m => m.ImageBig); | |
Map(m => m.DescriptionSmall); | |
Map(m => m.DescriptionBig); | |
Map(m => m.Evidence); | |
Map(m => m.Url); | |
References(m => m.Template); | |
} | |
} | |
public class TemplateMap : ClassMap<Template> | |
{ | |
public TemplateMap() | |
{ | |
Id(m => m.Id); | |
Map(m => m.Title).Unique(); | |
Map(m => m.Body); | |
Map(m => m.Css); | |
// References(m => m.TypeOfTemplate); | |
} | |
} | |
public class TemplateArticleMap : SubclassMap<TemplateArticle> | |
{ | |
} | |
public void TestMethod1() | |
{ | |
// create our NHibernate session factory | |
var sessionFactory = GetSessionFactory(); | |
using (var session = sessionFactory.OpenSession()) | |
{ | |
// populate the database | |
using (var transaction = session.BeginTransaction()) | |
{ | |
// create a fake Template | |
var template = new Template {Body = "this is a body", Title = " yeahh!!!"}; | |
session.SaveOrUpdate(template); | |
transaction.Commit(); | |
} | |
} | |
using (var session = sessionFactory.OpenSession()) | |
{ | |
// retreive all stores and display them | |
using (session.BeginTransaction()) | |
{ | |
var t = session.CreateCriteria(typeof(Template)).List<Template>().Single(); | |
Console.WriteLine("{0} : {1}", t.Title, t.Body); | |
} | |
} | |
} | |
public ISessionFactory GetSessionFactory() | |
{ | |
return Fluently.Configure() | |
.Database( | |
SQLiteConfiguration.Standard.InMemory() | |
.ShowSql()) | |
.Mappings(m => | |
m.FluentMappings.AddFromAssemblyOf<Template>()) | |
.ExposeConfiguration(config => new SchemaExport(config) | |
.Create(false, false)) | |
.BuildSessionFactory(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' unless defined?(Gem) | |
require 'mini_record' | |
require 'sqlite3' | |
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:" ) | |
class Template < ActiveRecord::Base | |
key :title, :css, :body | |
has_many :web_references | |
validates_presence_of :title, :body | |
end | |
class TemplateArticle < Template; end | |
class WebReference < ActiveRecord::Base | |
key :title, :sub_title, :image_small, :image_big, :description_small, :description_big, :evidence, :url | |
key :template, :as => :references | |
validates_presence_of :title | |
end | |
ActiveRecord::Base.auto_upgrade! | |
Template.create( :title => "yeahh!!", :body => "This is a body") | |
t = Template.first | |
puts "#{t.title} : #{t.body}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment