vendredi 28 août 2015

SQLite fluent join returns null

I just started using SQLite for nhibernate unit test cases. The interesting piece is that it works in my QA environment against our Oracle DB and it works using CreateSQLQuery against SQLite. I'm only having an issue when I'm using CreateCriteria(typeof(TEntity)).List().

Here is the SQLite setup.

private ISessionFactory SessionFactory { get; set; }
private Configuration Configuration { get; set; }

    public ISession CreateMockSession()
    {
        SessionFactory = CreateSessionFactory();
        return OpenSession();
    }

    private ISessionFactory CreateSessionFactory()
    {
        var c = Fluently.Configure()
                .Database( SQLiteConfiguration.Standard.InMemory().ShowSql() )
                .Mappings( m =>
                {
                    m.FluentMappings.Add<RppsPrivacyCcAccountNumberMap>();
                    m.FluentMappings.Add<RppsProposalMap>();
                } )
                .ExposeConfiguration( cfg => Configuration = cfg );
        return c.BuildSessionFactory();
    }

    private ISession OpenSession()
    {
        ISession session = SessionFactory.OpenSession();
        var export = new SchemaExport( Configuration );
        export.Execute( true, true, false, session.Connection, null );
        return session;
    }

Here are the mappings.

public class RppsProposalMap : ClassMap<RppsProposal>
{
    public RppsProposalMap()
    {
        Table( "RPPS_PROPOSAL" );

        Id( x => x.RppsProposalGid )
            .Column( "RPPS_PROPOSAL_GID" )
            .GeneratedBy.Native();
        Map( x => x.CurrentAccountNumberPID, "CURR_CC_ACCT_NBR_PID" );
        References( x => x.CurrentAccountNumber, "CURR_CC_ACCT_NBR_PID" )
            .PropertyRef( "AccountId" )
            .Fetch.Join()
            .Not.Insert()
            .Not.Update()
            .Not.Nullable();
    }


public class RppsPrivacyCcAccountNumberMap : ClassMap<RppsPrivacyCcAccountNumber>
{
    public RppsPrivacyCcAccountNumberMap()
    {
        Table( "RPPS_PRV_CC_ACCT_NBR" );

        Id( x => x.AccountId, "CC_ACCT_NBR_PID" )
            .GeneratedBy.Native();

        Map( x => x.AccountNumber, "CC_ACCT_NBR" );
    }
}

public class RppsProposal
    {
        public virtual long RppsProposalGid {get;set;}
        public virtual RppsPrivacyCcAccountNumber CurrentAccountNumber {get;set;}
        public virtual long CurrentAccountNumberPID {get;set;}
    }

    public class RppsPrivacyCcAccountNumber
    {
        public virtual long AccountId {get;set;}
        public virtual string AccountNumber {get;set;}
    }

The problem I'm getting is when I run Session.CreateCriteria(typeof(RppsProposal)).List() the CurrentAccountNumber is always null. I've run the SQL that nHibernate logs to the Test Explorer output and run it immediately after the CreateCriteria call and the account number is being returned.

Aucun commentaire:

Enregistrer un commentaire