CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Format:
Recent snippets matching tags of nhibernate
C#
private static ISessionFactory CreateSessionFactory()
{
    var cfg = new Configuration().Configure("nhibernate.config");
    cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionStringName, 
System.Configuration.ConfigurationManager.ConnectionStrings[System.Environment.MachineName].ConnectionString));
    return cfg.BuildSessionFactory();
}
by Robert.Eberhart   December 20, 2010 @ 8:33am
Tags: C#, NHibernate
183 Views
no comments
 
C#
namespace Northwind
{
    /// <summary>
    /// A base class for all entities that implements identity equality.
    /// </summary>
    /// <typeparam name="TId">The type of the ID.</typeparam>
    /// <typeparam name="T">The type of the derived class (required for equality)</typeparam>
    public abstract class EntityBase<TId, T> where T : EntityBase<TId, T>
    {
        private TId _id;
by Robert.Eberhart   December 20, 2010 @ 7:11am
Tags: NHibernate, C#, DDD
223 Views
no comments
 
C#
// pseudo: if month(entered) greater than or equal to 7, return year(entered)
// else return year(entered)-1 (for school year conversion)
// returns distinct list of "school years"
 
var criteria = Session.CreateCriteria<MyEntity>();
var convertToSchoolYearProjection = 
Projections.Conditional(
 Restrictions.Ge(
  Projections.SqlFunction("month", 
    NHibernateUtil.Int32, 
by David R. Longnecker   May 21, 2010 @ 7:58am
1273 Views
no comments
 
C#
class AuthorsByNameQuery   
{  
    internal DetachedCriteria Criteria;  
        
    public AuthorsByNameQuery()  
    {  
      Criteria = DetachedCriteria.For<Author>();  
    }  
          
    public IList<Author> List(ISession session)  
by darek156   May 17, 2010 @ 3:25am
144 Views
no comments
 
C#
public IQueryable<T> Query(Expression<Func<T, bool>> predicate)
{
    IQueryable<T> returnValue;
    using (ITransaction transaction = _session.BeginTransaction())
    {
        try
        {
            returnValue = _session.Linq<T>().Where(predicate);
            transaction.Commit();
        }
by Chris Brandsma   May 14, 2010 @ 2:09pm
273 Views
no comments
 
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
 
namespace Lucilla.Framework.Core.Data
{
    public static class QueryExtensions
    {
by andreabalducci   March 30, 2010 @ 9:24am
370 Views
no comments
 
C#
class Program
{
    private static ISessionFactory CreateSessionFactory()
    {
        return Fluently.Configure()
            .Database(
                OracleClientConfiguration
                    .Oracle10
                    .ConnectionString(Properties.Settings.Default.TWTest)
                    .ProxyFactoryFactory(typeof(NHibernate.ByteCode.LinFu.ProxyFactoryFactory)))
by Andy Sherwood   January 25, 2010 @ 4:42pm
1138 Views
no comments
 
C#
For<IUnitOfWork>()
    .LifecycleIs(new UniquePerRequestLifecycle())
    .Use(x => new UnitOfWork(x.GetInstance<ISessionFactory>(Keys.SessionFactoryName)));
by Mikael Henriksson   January 13, 2010 @ 3:43am
767 Views
no comments
 
C#
public List<PersonInOrganization> ExtractInvalidEmails()
{
  EntityCollection<PersonInOrganization> list =  GetAllItems();
 
  //my first LINQ use!
  var invalids = from l in list where !string.IsNullOrEmpty(l.Email) && !IsValidEmail(l.Email) select l;
 
  return invalids.ToList<PersonInOrganization>();
}
by afsharm   January 12, 2010 @ 12:01am
306 Views
1 comments
 
C#
public bool OnPreInsert(PreInsertEvent @event)
{
    var entity = @event.Entity as ParentVersion;
    if (entity == null)
    {
        return false;
    }
 
    var currentMaxVersion = @event.Session.CreateCriteria<ParentVersion>("pv")
        .Add(Restrictions.Eq("pv.Parent.Id", entity.Parent.Id))
by Mikael Henriksson   November 19, 2009 @ 1:09pm
187 Views
no comments
 
C#
public class ParentMap : ClassMap<Parent>
{
    public ParentMap()
    {
        Table("parent_def");      
        Id(x => x.Id,"parent_id");
        Map(x => x.UID, "parent_uid").CustomSqlType("varchar").Length(40);
        Map(x => x.DeletedAt ,"dte_deleted").Nullable();
        Map(x => x.ModifiedAt, "dte_modified").Nullable();
        Map(x => x.CreatedAt, "dte_created").Nullable();
by Mikael Henriksson   November 19, 2009 @ 5:42am
234 Views
no comments
 
C#
.Mappings(m => { 
                 m.FluentMappings.AddFromAssemblyOf<SomeMap>();
         m.AutoMappings.AddFromAssemblyOf<SomeOtherMap>();
            });
by Mikael Henriksson   November 12, 2009 @ 9:36am
337 Views
no comments
 
XML
<many-to-one cascade="all" update="false" insert="true" class="Data" foreign-key="backup_id" name="Data">
    <column name="backup_id" />
</many-to-one>
by Mikael Henriksson   November 11, 2009 @ 6:11am
191 Views
no comments
 
C#
string res = string.Empty;
 
try
{
    IQuery query = session.CreateQuery("select ao.CostCenterAccount from " +
                                       "AssetObservation as ao where ao.Asset.ID=:KEY " +
                                       "and ao.Date<:DATETIME order by Date asc");
    query.SetInt64("KEY", asset.Id);
    query.SetDateTime("DATETIME", dateTime);
by afsharm   November 01, 2009 @ 2:24am
627 Views
1 comments
 
C#
Configuration config = Fluently.Configure()
    .Database(MsSqlConfiguration.MsSql2008.ConnectionString(
                  c => c.FromConnectionStringWithKey("ConnectionString"))
                  .Cache(c =>
                         c.UseQueryCache()
                             .QueryCacheFactory<StandardQueryCacheFactory>()
                             .ProviderClass<HashtableCacheProvider>()
                             .UseMinimalPuts()
                  )
                  .UseReflectionOptimizer()
by Mikael Henriksson   October 25, 2009 @ 2:45am
229 Views
no comments
 
C#
new PersistenceSpecification<Component>(session, new ComponentEqualityComparer())
 
public class ComponentEqualityComparer : IEqualityComparer
{
    #region IEqualityComparer Members
 
    public bool Equals(object x, object y)
    {
        if (x == null || y == null)
        {
by Mikael Henriksson   October 13, 2009 @ 3:15am
194 Views
no comments
 
C#
private static ISessionFactory CreateSessionFactory()
       {
           return Fluently.Configure()
               .Database(MsSqlConfiguration.MsSql2008
                   .ConnectionString(c => c
                        .FromConnectionStringWithKey("MyStore.Properties.Settings.StoreConnectionString"))
                        )
               .Mappings(m =>
                   m.FluentMappings
                       .AddFromAssemblyOf<Program>())
by Mikael Henriksson   October 07, 2009 @ 11:13pm
223 Views
no comments
 
C#
public class XmlType : IUserType
{
    public new bool Equals(object x, object y)
    {
        if (x == null || y == null)
            return false;
 
        var xdoc_x = (XmlDocument)x;
        var xdoc_y = (XmlDocument)y;
        return xdoc_y.OuterXml == xdoc_x.OuterXml;
by Mikael Henriksson   September 23, 2009 @ 1:17pm
500 Views
no comments
 
C#
public static class ExtensionMethods
{
    public static Configure FluentSagaPersister(this Configure config)
    {
        ISessionFactory sessionFactory = FluentConfig.GetFluentSessionFactory();
        config.Configurer.RegisterSingleton<ISessionFactory>(sessionFactory);
        config.Configurer.ConfigureComponent<FluentSagaPersister>(ComponentCallModelEnum.Singlecall);
 
        return config;
    }
by Mikael Henriksson   September 20, 2009 @ 3:56am
280 Views
no comments
 
C#
public class FluentSagaPersister : ISagaPersister
{
    /// <summary>
    /// Injected session factory.
    /// </summary>
    public ISessionFactory SessionFactory { get; set; }
 
    #region ISagaPersister Members
 
    public void Save(ISagaEntity saga)
by Mikael Henriksson   September 20, 2009 @ 3:48am
313 Views
no comments
 
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate