本文整理汇总了C#中ISessionFactory.GetAllClassMetadata方法的典型用法代码示例。如果您正苦于以下问题:C# ISessionFactory.GetAllClassMetadata方法的具体用法?C# ISessionFactory.GetAllClassMetadata怎么用?C# ISessionFactory.GetAllClassMetadata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISessionFactory
的用法示例。
在下文中一共展示了ISessionFactory.GetAllClassMetadata方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetValidatorFromSession
public static Core.Validator GetValidatorFromSession(ISessionFactory sessionFactory)
{
var allDefindedClasses = sessionFactory.GetAllClassMetadata();
Core.Validator validator = new Core.Validator();
foreach (KeyValuePair<string, IClassMetadata> pair in allDefindedClasses)
{
IClassMetadata metadata = pair.Value;
foreach (string propertyName in metadata.PropertyNames)
{
IType propertyType = metadata.GetPropertyType(propertyName);
StringType st = propertyType as StringType;
if (st != null)
{
if (st.SqlType.Length > 0)
{
validator.AddRule(Rule.For(metadata.GetMappedClass(EntityMode.Poco))
.OnMember(propertyName)
.MaxLength(st.SqlType.Length)
.Message(String.Format(
"Property {0} have a maximum length of {1}",
propertyName,
st.SqlType.Length)));
}
}
}
}
return validator;
}
示例2: ODataSessionFactoryContext
public ODataSessionFactoryContext(ISessionFactory sessionFactory)
{
Require.NotNull(sessionFactory, "sessionFactory");
MappedClassMetadata = sessionFactory.GetAllClassMetadata().Values.ToDictionary(
x => x.GetMappedClass(EntityMode.Poco),
x => new MappedClassMetadata(x)
);
}
示例3: ClearSecondLevelCache
public static void ClearSecondLevelCache(ISessionFactory sessionFactory)
{
var classMetadata = sessionFactory.GetAllClassMetadata();
foreach (var ep in classMetadata.Values) {
sessionFactory.EvictEntity(ep.EntityName);
}
var collMetadata = sessionFactory.GetAllCollectionMetadata();
foreach (var acp in collMetadata.Values) {
sessionFactory.EvictCollection(acp.Role);
}
}
示例4: GetSchema
public static List<ExplorerItem> GetSchema(ISessionFactory sessionFactory)
{
var items = sessionFactory.GetAllClassMetadata().Values
.Select(x => new ExplorerItem(x.EntityName, ExplorerItemKind.QueryableObject, ExplorerIcon.Table)
{
Children = x.PropertyNames.Select(p => GetPropertyItem(x, p)).ToList(),
Tag = x.GetMappedClass(EntityMode.Poco)
}).ToList();
foreach (var property in items.SelectMany(x => x.Children))
{
var type = (IType)property.Tag;
var manyToOne = type as ManyToOneType;
if (manyToOne != null)
property.HyperlinkTarget = items.Single(x => Equals(x.Tag, type.ReturnedClass));
}
return items;
}
示例5: Register
/// <summary>
/// 지정된 <see cref="ISessionFactory"/> 인스턴스에 등록된 모든 NHibernate용 Entity를 조사해서,
/// 자동으로 Generic Dao (INHRepository{T} 구현 클래스)를 <see cref="IKernel"/>에 Component로 등록한다.
/// 이렇게 하면, NHRepository{T} 하나만 만들고, 실제 Entity별의 NHRepository는 Castle에 자동으로 등록되고, Instancing될 것이다!!!
/// (예 NHRepository{Blog}, NHRepository{Customer} 등을 Castle Component로 정의하지 않아도, 이 함수에서 자동으로 조사하여, IoC에 등록시켜 준다는 뜻!!!)
/// </summary>
/// <param name="sessionFactory">NHibernate Session Factory</param>
/// <param name="kernel">Castle.MicroKernel 인스턴스</param>
/// <param name="repositoryType">INHRepository{T} 를 구현한 Concrete Class Type</param>
/// <param name="isCandidateForRepository">NHibernate의 매핑된 Entity 중에 IoC Container에 등록할 Type을 선별하는 Predicator</param>
public static void Register(IKernel kernel,
ISessionFactory sessionFactory,
Type repositoryType,
Predicate<Type> isCandidateForRepository) {
if(IsDebugEnabled)
log.Debug("NHibernate SessionFactory에 등록된 Entity Class에 대한 " +
@"Generic Repository (INHRepository<TEntity>) 의 인스턴스를 생성합니다. repositoryType=[{0}]", repositoryType);
if(IsImplementsOfGenericNHRepository(repositoryType) == false)
throw new InvalidOperationException("Repository must be a type inheriting from INHRepository<T>, " +
"and must be an open generic type. Sample: typeof(NHRepository<>).");
// GetAllClassMetadata 는 IDictionary<Type, IClassMetadata> 이고 Type은 Mapping된 entity의 Type이다.
//
foreach(IClassMetadata meta in sessionFactory.GetAllClassMetadata().Values) {
var mappedClass = meta.GetMappedClass(EntityMode.Poco);
if(mappedClass == null)
continue;
foreach(Type interfaceType in mappedClass.GetInterfaces()) {
if(isCandidateForRepository(interfaceType)) {
if(IsDebugEnabled)
log.Debug("Register Generic Repository. INHRepository<{0}>", interfaceType.FullName);
// NOTE : INHRepository<TEnitity> 는 꼭 ConcreteType 속성 (Entity의 Type) 을 가져야한다.
//
kernel.Register(
Component
.For(typeof(INHRepository<>).MakeGenericType(interfaceType))
.ImplementedBy(repositoryType.MakeGenericType(interfaceType))
.DependsOn(Dependency.OnValue("ConcreteType", mappedClass))
.OnlyNewServices());
//.DependsOn(Property.ForKey("ConcreteType").Eq(mappedClass))
//.Unless(Component.ServiceAlreadyRegistered));
}
}
}
}
示例6: Register
/// <summary>
/// Registers the interfaces of the entities defined in the session factory in the kernel.
/// </summary>
/// <param name="kernel">The kernel.</param>
/// <param name="sessionFactory">The session factory.</param>
/// <param name="repository">The repository type to map to <seealso cref="IRepository{T}"/>.</param>
/// <param name="isCandidateForRepository">The is candidate for repository.</param>
/// <remarks>
/// The reason that we have the <paramref name="isCandidateForRepository"/> is to avoid registering services
/// for interfaces that are not related to the domain (INotifyPropertyChanged, as a good example).
/// </remarks>
public static void Register(
IKernel kernel,
ISessionFactory sessionFactory,
Type repository,
IsCandidateForRepositoryDelegate isCandidateForRepository
)
{
if (ImplementsOpenIRepository(repository) == false)
throw new ArgumentException("Repository must be a type inheriting from IRepository<T>, and must be an open generic type. Sample: typeof(NHRepository<>).");
foreach (IClassMetadata meta in sessionFactory.GetAllClassMetadata().Values)
{
Type mappedClass = meta.GetMappedClass(EntityMode.Poco);
if (mappedClass == null)
continue;
foreach (Type interfaceType in mappedClass.GetInterfaces())
{
if (isCandidateForRepository(interfaceType, mappedClass) == false)
continue;
kernel.Register(
Component.For(typeof(IRepository<>).MakeGenericType(interfaceType))
.ImplementedBy(repository.MakeGenericType(interfaceType))
.DependsOn(Property.ForKey("ConcreteType").Eq(mappedClass))
);
}
}
}