本文整理汇总了C#中NHibernate类的典型用法代码示例。如果您正苦于以下问题:C# NHibernate类的具体用法?C# NHibernate怎么用?C# NHibernate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NHibernate类属于命名空间,在下文中一共展示了NHibernate类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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");
}
开发者ID:5509850,项目名称:baumax,代码行数:7,代码来源:PKGen.cs
示例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)};
}
开发者ID:mbsky,项目名称:dotnetmarcheproject,代码行数:14,代码来源:SqlFunctionCriterion.cs
示例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;
}
开发者ID:julienblin,项目名称:Colibri,代码行数:26,代码来源:AuditInterceptor.cs
示例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();
}
开发者ID:bibliopedia,项目名称:bibliopedia,代码行数:8,代码来源:IdentifiableIdGenerator.cs
示例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);
}
开发者ID:jhuerta,项目名称:Tutorial_Summer_Of_NHibernate,代码行数:25,代码来源:MyInterceptor.cs
示例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;
}
}
开发者ID:spc-ofp,项目名称:tubs-data-clr,代码行数:32,代码来源:AccessControlEventListener.cs
示例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);
}
开发者ID:lgatto,项目名称:proteowizard,代码行数:25,代码来源:GroupingControlForm.cs
示例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);
}
开发者ID:hazzik,项目名称:nhcontrib-all,代码行数:25,代码来源:OneToOneNotOwningMapper.cs
示例9: OnPrepareStatement
OnPrepareStatement(NHibernate.SqlCommand.SqlString sql)
{
System.Diagnostics.Debug.WriteLine("NH: " + sql);
if (_log.IsDebugEnabled)
_log.Debug(sql);
return base.OnPrepareStatement(sql);
}
开发者ID:TicketArchitecture,项目名称:Api-Template,代码行数:7,代码来源:SQLDebugOutputLogger.cs
示例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;
}));
}
开发者ID:urmilaNominate,项目名称:mERP-framework,代码行数:32,代码来源:DbHelper2.cs
示例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()));
}
开发者ID:RobertMischke,项目名称:Seedworks,代码行数:7,代码来源:ConditionAvgAggregate.cs
示例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;
}
开发者ID:adbrowne,项目名称:FubuMovies,代码行数:7,代码来源:NHibernateConfiguration.cs
示例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");
}
开发者ID:navneetccna,项目名称:n2cms,代码行数:31,代码来源:ClassMappingGenerator.cs
示例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;
}
开发者ID:TimBarcz,项目名称:groop,代码行数:28,代码来源:HybridSessionBuilder.cs
示例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;
}
开发者ID:debop,项目名称:NFramework,代码行数:10,代码来源:EntityStateInterceptor.cs
示例16: OnSave
public override bool OnSave(object entity, object id, object[] state, string[] propertyNames, NHibernate.Type.IType[] types)
{
{
for (var i = 0; i < state.Length; i++)
{
switch (propertyNames[i])
{
case "CreatedOn":
state[i] = state[i] ?? DateTime.UtcNow;
break;
case "CreatedBy":
state[i] = state[i] ?? CurrentUser.Identity.Name;
break;
case "ModifiedOn":
state[i] = DateTime.UtcNow;
break;
case "ModifiedBy":
state[i] = CurrentUser.Identity.Name;
break;
}
}
return base.OnSave(entity, id, state, propertyNames, types);
}
}
开发者ID:codeprogression,项目名称:Fluently-Persistent,代码行数:25,代码来源:DefaultInterceptor.cs
示例17: GetRows
public static IList<Row> GetRows (NHibernate.ISession session, DataFilter dataFilter)
{
lock (session)
return dataFilter.Analysis.First().Parameters
.Select(o => new AnalysisParameterRow(o, dataFilter) as Row)
.ToList();
}
开发者ID:lgatto,项目名称:proteowizard,代码行数:7,代码来源:AnalysisTableForm.cs
示例18: 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();
}
return sc;
}).ToArray();
var dbg = m.AsString();
cfg.AddDeserializedMapping(m, "N2");
}
开发者ID:amarwadi,项目名称:n2cms,代码行数:28,代码来源:ClassMappingGenerator.cs
示例19: BuildSchema
protected virtual void BuildSchema(NHib.Cfg.Configuration config)
{
// this NHibernate tool takes a configuration (with mapping info in)
// and exports a database schema from it
new SchemaExport(config)
.Create(false, false);
}
开发者ID:UrK,项目名称:kululu_v1,代码行数:7,代码来源:NHibernateSessionFactory.cs
示例20: 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.Criterion.ICriteriaQuery criteriaQuery)
{
return new TypedValue[] {
new TypedValue(GetITypeFromCLRType(mValueToCompareTo.GetType()), mValueToCompareTo, EntityMode.Poco)};
}
开发者ID:mbsky,项目名称:dotnetmarcheproject,代码行数:14,代码来源:SqlFunctionCriterion.cs
注:本文中的NHibernate类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论