Roger,
Actually, I have to say I'm sorry first, I was only testing
GetCurrentRevision... Other querys "work".
- *session.Auditer().GetCurrentRevision(false)* returns Id = 0 and date
= now;
-
*session.Auditer().CrossTypeRevisionChangesReader().FindEntities(3,RevisionType.Modified)
*returns "query did not return a unique result: 3". Actually there are 2
records for revision 3 in RevChanges table. How should I execute this
query? I'm doing it like it is said in the docs.
- *session.Auditer().GetRevisionNumberForDate(new DateTime(2014, 02,
17,15,55,03,503,DateTimeKind.Local)) *returns "query did not return a
unique result: 2". There's only one record in Revinfo for this exact
datetime.
- *session.Auditer().GetRevisions(typeof (ItemDeConfiguracao), 1) *returns
6 records (it looks like its something with it's query's inner/left join):
- Name - Value
- [0] - 1
- [1] - 3
- [2] - 4
- [3] - 1
- [4] - 3
- [5] - 4
This is my nhibernate session factory:
public static ISessionFactory SessionFactory
{
get
{
try
{
if (_sessionFactory == null)
{
lock (SyncRoot)
{
_sessionFactory = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008.Dialect<CustomMsSql2008Dialect>()
//.ConnectionString(c =>
c.FromConnectionStringWithKey("DBSQL_AUDIT")).ShowSql())
.ConnectionString(c =>
c.FromConnectionStringWithKey("DBSQL")).ShowSql())
.Mappings(m =>
m.FluentMappings.AddFromAssemblyOf<NHibernateHelper>())
.ExposeConfiguration(ConfigurarEnvers)
//.ExposeConfiguration(c => new
SchemaExport(c).SetOutputFile(@"C:\Temp\scripteste.txt").Execute(true,
true, false))
.BuildSessionFactory();
}
}
return _sessionFactory;
}
catch (FluentConfigurationException ex)
{
// Log.Fatal(ex);
throw new Exception("Não foi possível conectar-se ao
banco de dados. Favor entrar em contato com o administrador do sistema.",
ex);
}
}
}
private static void ConfigurarEnvers(Configuration cfg)
{
var enversConf = new
NHibernate.Envers.Configuration.Fluent.FluentConfiguration();
var rev = new RevInfoListener();
enversConf.Audit(Dominio.Classes.Helper.ObterSubClassesDeEntidadeBase());
cfg.SetEnversProperty(ConfigurationKey.TrackEntitiesChangedInRevision,
true);
cfg.SetEnversProperty(ConfigurationKey.DefaultSchema, "dbo");
cfg.SetEnversProperty(ConfigurationKey.DefaultCatalog,
"DB_AUDIT");
cfg.IntegrateWithEnvers(enversConf);
}
And this is my Custom REVINFO class
[RevisionEntity(typeof(RevInfoListener))]
public class REVINFO : DefaultTrackingModifiedEntitiesRevisionEntity
{
public virtual string Usuario { get; set; }
}
RevInfoListener
public class RevInfoListener : IRevisionListener
{
public void NewRevision(object revisionEntity)
{
var usuario = Thread.CurrentPrincipal.Identity.Name;
((REVINFO)revisionEntity).Usuario = usuario;
}
}
And REVINFOMap. The value returned by
configurationmanager.appsettings["BandoDeDadosAuditoria"] is
"DB_AUDIT.dbo". It's the catalog and schema name. It's the way I found to
force it uses the Audit database for querying, otherwise it will try to
query from the Session's catalog.
public class REVINFOMap : ClassMap<REVINFO>
{
public REVINFOMap()
{
var bdAudit =
ConfigurationManager.AppSettings["BancoDeDadosAuditoria"];
Schema(bdAudit);
Table("REVINFO");
Id(x => x.Id, "REV").GeneratedBy.Identity();
Map(x => x.RevisionDate, "REVTSTMP");
Map(x => x.Usuario, "Usuario");
}
}
Btw, The "Usuario" field is being inserted as NULL... It worked before I
activated the TrackEntitiesChangedInRevision setting.
And please don't ask me to post an Isolated Test or whatever... Our code is
a total mess right now and for some freaking reason, an error is occurring
when I try to open a session in test environment. We're on a total rush
here. The company's president is on our asses these days. Yep, the
president.
thanks a lot in advance!
On Tuesday, February 18, 2014 7:28:59 AM UTC-3, Roger wrote:
>
> AFAIK, that ”should” work. Is it one specific query that doesn’t work or
> is it all of them?
>
>
>
> How is your configuration object configured?
>
>
>
> *From:* [email protected] <javascript:> [mailto:
> [email protected] <javascript:>] *On Behalf Of *Guilherme Paschoal
> *Sent:* den 17 februari 2014 21:17
> *To:* [email protected] <javascript:>
> *Subject:* [nhusers] [Envers] Query from different catalog
>
>
>
> Hello guys!
>
>
>
> I successfully got envers to work, saving to a different catalog.
>
>
>
> My problem is that unfortunately, querying from that catalog, won't work.
> It queries from the current session's catalog, not from the one I
> configured in "cfg.SetEnversProperty(ConfigurationKey.DefaultCatalog,
> "DB_AUDIT");".
>
>
>
> I've been searching around envers source but I couldn't find any tips on
> that.
>
>
>
> Anyone got that one working or has any tips for me?
>
>
>
> Thanks a lot in advance!
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "nhusers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected] <javascript:>.
> To post to this group, send email to [email protected] <javascript:>
> .
> Visit this group at http://groups.google.com/group/nhusers.
> For more options, visit https://groups.google.com/groups/opt_out.
>
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/groups/opt_out.