本文整理汇总了C#中NHibernate类的典型用法代码示例。如果您正苦于以下问题:C# NHibernate类的具体用法?C# NHibernate怎么用?C# NHibernate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NHibernate类属于命名空间,在下文中一共展示了NHibernate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Generate
public object Generate(NHibernate.Engine.ISessionImplementor session, object obj)
{
// can operate more handy with "obj", when all entities will be inherited from
// common base class
// todo: ?implement somewhere const for "Entities" string?
return PKGenDao.GetNextPK("Entities");
}
示例2: GetTypedValues
/// <summary>
/// Returns to nhibernate the type of the parameters.
/// I need only one operator.
/// </summary>
/// <param name="criteria"></param>
/// <param name="criteriaQuery"></param>
/// <returns></returns>
public override NHibernate.Engine.TypedValue[] GetTypedValues(
NHibernate.ICriteria criteria,
NHibernate.Expressions.ICriteriaQuery criteriaQuery)
{
return new TypedValue[] {
new TypedValue(GetITypeFromCLRType(mValueToCompareTo.GetType()), mValueToCompareTo)};
}
示例3: OnFlushDirty
public override bool OnFlushDirty(object entity, object id, object[] currentState, object[] previousState, string[] propertyNames, NHibernate.Type.IType[] types)
{
IAuditable auditable = entity as IAuditable;
if (auditable != null)
{
IClock clock = kernel.Resolve<IClock>();
IApplicationContext appContext = kernel.Resolve<IApplicationContext>();
currentState[Array.IndexOf<string>(propertyNames, "UpdatedAt")] = clock.Now;
currentState[Array.IndexOf<string>(propertyNames, "UpdatedBy")] = appContext.FullUserName;
Project auditProject = auditable.AuditProject;
if (auditProject != null)
{
ProjectHistoryStep historyStep = new ProjectHistoryStep();
historyStep.Description = string.Format("Updated {0}", auditable.HistoryDescription);
historyStep.At = clock.Now;
historyStep.By = appContext.FullUserName;
historyStep.Project = auditProject;
historyStep.Create();
}
return true;
}
return false;
}
示例4: Generate
// this piece of code was difficult for me to come up with.
public object Generate(NHibernate.Engine.ISessionImplementor session, object obj)
{
var record = obj as IIdentifiable;
if (record == null) throw new ArgumentOutOfRangeException("obj");
return record.ComputeIdentity();
}
示例5: OnFlushDirty
public override bool OnFlushDirty(
object entity,
object id,
object[] currentState,
object[] previousState,
string[] propertyNames,
NHibernate.Type.IType[] types)
{
if (previousState != null)
{
for (int i = 0; i < propertyNames.Length; i++)
{
string msg = string.Format(">>>>-->>>>> {0}: Previous Name = {1} , Curr Value = {2}",
propertyNames[i],
previousState[i],
currentState[i]);
//System.Diagnostics.Debug.WriteLine(msg);
System.Diagnostics.Trace.WriteLine(msg);
Trace.WriteLine(msg);
}
}
return base.OnFlushDirty(entity, id, currentState, previousState, propertyNames, types);
}
示例6: OnLoad
public void OnLoad(NHibernate.Event.LoadEvent @event, LoadType loadType)
{
if (null == @event.Result)
return;
// Short circuit
if (!ShouldContinue(@event.Session, @event.Result.GetType()))
return;
ISecurable securable = @event.Result as ISecurable;
if (null == securable)
{
// TODO: Consider making this an Exception...
System.Console.WriteLine("Implements ISecurable but can't be cast as ISecurable...");
return;
}
// Attempt at fixing the Day->Trip problem...
if ("InternalLoadLazy".Equals(loadType.ToString()))
return;
var entityName = @event.Session.GetFilterParameterValue("EntityNameFilter.EntityName") as string;
//bool canLoad = securable.GetAccessList().Where(ace => ace.EntityName == entityName).Any();
System.Console.WriteLine("ACL size: {0}", securable.AccessControlList.Count());
bool canLoad = securable.IsLoadableFor(entityName);
System.Console.WriteLine("loadType {0}\tLockMode: {1}", loadType, @event.LockMode);
System.Console.WriteLine("CanLoad entity {2} for organization [{0}]? {1}", entityName, canLoad, @event.Result.GetType().FullName);
if (!canLoad)
{
@event.Result = null;
}
}
示例7: GroupingControlForm
public GroupingControlForm(NHibernate.ISessionFactory sessionFactory)
{
InitializeComponent();
this.session = sessionFactory.OpenSession();
tlvGroupedFiles.CanExpandGetter += x => (((tlvBranch)x).Data is SpectrumSourceGroup && ((tlvBranch)x).Children.Any());
tlvGroupedFiles.ChildrenGetter += getChildren;
tlvGroups.AspectGetter += x =>
{
var nodeTracker = ((tlvBranch) x);
var offsetCorrection = 0;
while (nodeTracker.Parent.Text != null)
{
offsetCorrection++;
nodeTracker = nodeTracker.Parent;
}
return ((tlvBranch) x).Text + new string(' ',offsetCorrection*7);
};
tlvGroups.AutoCompleteEditor = false;
tlvGroups.ImageGetter += delegate(object x) { return (((tlvBranch)x).Data is SpectrumSourceGroup) ? Properties.Resources.XPfolder_closed : Properties.Resources.file; };
ApplyDefaultGroups(null, null);
}
示例8: MapToEntityFromMap
public void MapToEntityFromMap(NHibernate.Envers.Configuration.AuditConfiguration verCfg, object obj, IDictionary<object, object> data, object primaryKey, NHibernate.Envers.Reader.IAuditReaderImplementor versionsReader, long revision)
{
// //TODO in implementing second phase/////////////
//if (obj == null) {
// return;
// }
////System.Type entityClass = ReflectionTools.loadClass(owningEntityName);
// System.Runtime.Remoting.ObjectHandle hdl = Activator.CreateInstance(owningEntityName);
// System.Type entityClass = hdl.GetType();
// Object value;
// try {
// value = versionsReader.CreateQuery().ForEntitiesAtRevision(entityClass, revision)
// .Add(AuditEntity.relatedId(owningReferencePropertyName).eq(primaryKey)).GetSingleResult();
// } catch (NoResultException e) {
// value = null;
// } catch (NonUniqueResultException e) {
// throw new AuditException("Many versions results for one-to-one relationship: (" + owningEntityName +
// ", " + owningReferencePropertyName + ")");
// }
// Setter setter = ReflectionTools.getSetter(obj.getClass(), propertyData);
// setter.set(obj, value, null);
}
示例9: OnPrepareStatement
OnPrepareStatement(NHibernate.SqlCommand.SqlString sql)
{
System.Diagnostics.Debug.WriteLine("NH: " + sql);
if (_log.IsDebugEnabled)
_log.Debug(sql);
return base.OnPrepareStatement(sql);
}
示例10: UpdateTransaction
/// <summary>
/// 采用NHibernate的Transaction
/// 在外部开始Transaction,外部处理Exception
/// </summary>
/// <param name="cmds"></param>
/// <param name="session"></param>
public static void UpdateTransaction(ICollection<MyDbCommand> cmds, NHibernate.ISession session)
{
if (cmds == null)
{
throw new ArgumentNullException("cmds");
}
if (cmds.Count == 0)
{
return;
}
if (session == null)
{
throw new ArgumentNullException("session");
}
DbConnection conn = session.Connection as DbConnection;
if (conn == null)
{
throw new NotSupportedException("session must be DbConnection session");
}
DbHelper.UpdateTransaction(cmds, new DbHelper.SetCommand(delegate(MyDbCommand cmd)
{
session.Transaction.Enlist(cmd.Command);
cmd.Command.Connection = conn;
}));
}
示例11: AddToCriteria
public override void AddToCriteria(NHibernate.ICriteria criteria)
{
if (IsGreaterThan())
criteria.Add(Restrictions.Gt(_Projections.EmptyGroupDoubleAvg(PropertyName), GetValue()));
else
criteria.Add(Restrictions.Lt(_Projections.EmptyGroupDoubleAvg(PropertyName), GetValue()));
}
示例12: ConfigureDataAccess
public static void ConfigureDataAccess(IPersistenceConfigurer databaseConfigurer, InstanceScope sessionScope, out NHibernate.Cfg.Configuration cfg)
{
NHibernate.Cfg.Configuration configuration = null;
ObjectFactory.Initialize(i => ConfigureDataAccess(i, databaseConfigurer, sessionScope, out configuration));
ObjectFactory.AssertConfigurationIsValid();
cfg = configuration;
}
示例13: MapTypes
public virtual void MapTypes(List<Type> allTypes, NHibernate.Cfg.Configuration cfg, Func<string, string> formatter)
{
var m = new HbmMapping();
m.Items = allTypes.Select(t =>
{
var sc = new HbmSubclass();
sc.name = GetName(t);
sc.extends = GetName(t.BaseType);
sc.discriminatorvalue = map.GetOrCreateDefinition(t).Discriminator ?? t.Name;
sc.lazy = false;
sc.lazySpecified = true;
var propertyMappings = GetPersistables(t)
.Select(p => p.Attribute.GetPropertyMapping(p.DeclaringProperty, formatter))
.ToList();
if (propertyMappings.Count > 0)
{
if (sc.Items == null)
sc.Items = propertyMappings.ToArray();
else
sc.Items = sc.Items.Union(propertyMappings).ToArray();
}
logger.DebugFormat("Generating subclass {0} with discriminator {1} extending {2} with {3} items ({4} property mappings)", sc.name, sc.discriminatorvalue, sc.extends, sc.Items != null ? sc.Items.Length.ToString() : "(null)", propertyMappings.Count);
return sc;
}).ToArray();
if (Debugger.IsAttached)
{
var dbg = m.AsString();
}
cfg.AddDeserializedMapping(m, "N2");
}
示例14: getExistingOrNewSession
private ISession getExistingOrNewSession(NHibernate.ISessionFactory factory)
{
if (HttpContext.Current != null)
{
ISession session = GetExistingWebSession();
if (session == null)
{
session = openSessionAndAddToContext(factory);
}
else if (!session.IsOpen)
{
session = openSessionAndAddToContext(factory);
}
return session;
}
if (currentSession == null)
{
currentSession = factory.OpenSession();
}
else if (!currentSession.IsOpen)
{
currentSession = factory.OpenSession();
}
return currentSession;
}
示例15: OnSave
/// <summary>
/// Occurred when the specified entity is saved.
/// </summary>
public override bool OnSave(object entity, object id, object[] state, string[] propertyNames,
NHibernate.Type.IType[] types) {
if(entity is IStateEntity)
return ((IStateEntity)entity).IsSaved = true;
return false;
}