當前位置: 首頁>>代碼示例>>C#>>正文


C# AutoPersistenceModel.AddMappingsFromAssembly方法代碼示例

本文整理匯總了C#中AutoPersistenceModel.AddMappingsFromAssembly方法的典型用法代碼示例。如果您正苦於以下問題:C# AutoPersistenceModel.AddMappingsFromAssembly方法的具體用法?C# AutoPersistenceModel.AddMappingsFromAssembly怎麽用?C# AutoPersistenceModel.AddMappingsFromAssembly使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在AutoPersistenceModel的用法示例。


在下文中一共展示了AutoPersistenceModel.AddMappingsFromAssembly方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: BuildPersistenceModel

        public AutoPersistenceModel BuildPersistenceModel()
        {
            var persistenceModel = new AutoPersistenceModel();

            persistenceModel.Conventions.Setup(c =>
            {
                c.Add(typeof(ForeignKeyNameConvention));
                c.Add(typeof(ReferenceConvention));
                c.Add(typeof(PrimaryKeyNameConvention));
                c.Add(typeof(TableNameConvention));
            });

            persistenceModel.AddMappingsFromAssembly(AssemblyMapper);

            persistenceModel.WriteMappingsTo(@"./");

            return persistenceModel;
        }
開發者ID:thangchung,項目名稱:NHibernate3Sample,代碼行數:18,代碼來源:NHibernateComponentModule.cs

示例2: GetHBMFilesForFluentFromCSProj

        public static IEnumerable<string> GetHBMFilesForFluentFromCSProj(CSProjFile csproj, string outputPath)
        {
            string assemblyName = csproj.GetAssemblyName();
            IEnumerable<string> outputPaths = csproj.GetOutputPaths();
            DateTime latestAssemblyDate = new DateTime(1900, 1, 1);
            string latestAssembly = "";

            foreach (string folder in outputPaths)
            {
                string assemblyPath = Path.Combine(folder, assemblyName);

                if (File.Exists(assemblyPath))
                {
                    DateTime lastWriteTime = File.GetLastWriteTimeUtc(assemblyPath);

                    if (lastWriteTime > latestAssemblyDate)
                    {
                        latestAssemblyDate = lastWriteTime;
                        latestAssembly = assemblyPath;
                    }
                }
            }
            if (string.IsNullOrEmpty(latestAssembly))
                throw new FluentNHibernateCompiledAssemblyMissingException("No compiled assembly found. A compiled assembly is required for Fluent NHibernate. Please recompile your project.");

            System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFrom(latestAssembly);
            FluentCompileLatestAssemblyDir = Path.GetDirectoryName(latestAssembly);

            try
            {
                assembly.ModuleResolve += new System.Reflection.ModuleResolveEventHandler(assembly_ModuleResolve);
                AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
                AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += new ResolveEventHandler(CurrentDomain_ReflectionOnlyAssemblyResolve);

                if (!Directory.Exists(outputPath))
                    Directory.CreateDirectory(outputPath);

                //var sessionFactory = FluentNHibernate.Cfg.Fluently.Configure()
                //                  .Database(FluentNHibernate.Cfg.Db.MsSqlConfiguration.MsSql2008
                //                    .ConnectionString("Data Source=STN_DEV;Initial Catalog=FNHProviderDB;Integrated Security=SSPI;")
                //                  )
                //                  .Mappings(m => m.FluentMappings.AddFromAssembly(assembly).ExportTo(outputPath))
                //                  .BuildConfiguration();

                AutoPersistenceModel mappings = new AutoPersistenceModel();
                mappings.AddMappingsFromAssembly(assembly);
                mappings.BuildMappings();
                mappings.WriteMappingsTo(outputPath);

                return Directory.GetFiles(outputPath).ToList();
            }
            finally
            {
                assembly.ModuleResolve -= assembly_ModuleResolve;
                AppDomain.CurrentDomain.AssemblyResolve -= CurrentDomain_AssemblyResolve;
                AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve -= CurrentDomain_ReflectionOnlyAssemblyResolve;
            }
        }
開發者ID:uQr,項目名稱:Visual-NHibernate,代碼行數:58,代碼來源:ProjectLoader.cs


注:本文中的AutoPersistenceModel.AddMappingsFromAssembly方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。