/// <summary>
        /// 创建一个数据提供者实例
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="repUri"></param>
        /// <returns></returns>
        public static T Create <T>(string connStr) where T : class
        {
            T instance = null;

            try
            {
                Assembly asm = Assembly.GetExecutingAssembly(); // Assembly.Load("LJH.Inventory.DAL");
                if (asm != null)
                {
                    foreach (Type t in asm.GetTypes())
                    {
                        if (t.IsClass && !t.IsAbstract)
                        {
                            foreach (Type inter in t.GetInterfaces())
                            {
                                if (inter == typeof(T))
                                {
                                    Stream        stream        = asm.GetManifestResourceStream("LJH.Inventory.DAL.LinqProvider.Inventory.xml");
                                    MappingSource mappingSource = XmlMappingSource.FromStream(stream);
                                    instance = Activator.CreateInstance(t, connStr, mappingSource) as T;
                                    return(instance);
                                }
                            }
                        }
                    }
                }
            }
            catch
            {
            }
            throw new Exception(string.Format("没有找到 {0} ,请确保 {1} 已经存在!", typeof(T).FullName, typeof(T).FullName));
        }
Exemplo n.º 2
0
        // Temp constructor till I get IOC wired up
        public ProcessLogViewModel()
        {
            var databaseConfigFileName = "EdhLogViewer.database.config";
            var installationDirectory  = @"c:\Dev\EdhLogViewer\DataAccess";
            var databaseConfig         = System.IO.Path.Combine(installationDirectory, databaseConfigFileName);
            var mappingSource          = XmlMappingSource.FromUrl(databaseConfig);

            EdhLogDataContext = new EdhLogDataContext("Data Source=EDHDBSIT01,65000;Initial Catalog=ODS_SIT01;Integrated Security=True", mappingSource, false, 60);


            RetrieveByProcessNameCommand = new DelegateCommand <string>(new Action <string>(i =>
            {
                LogMessages = new ObservableCollection <ProcessLog>(EdhLogDataContext.NameStartsWithQuery(i));
                OnPropertyChanged("LogMessages");
            }));

            RetrieveByParamsCommand = new DelegateCommand <QueryParamsViewModel>(new Action <QueryParamsViewModel>(i =>
            {
                var queryParams         = new QueryParams();
                queryParams.ProcessName = i.ProcessName;

                queryParams.StartDate = i.FromDateTime;
                queryParams.EndDate   = i.ToDateTime;

                LogMessages = new ObservableCollection <ProcessLog>(EdhLogDataContext.ParamsQuery(queryParams));
                OnPropertyChanged("LogMessages");
            }));

            QueryParamsViewModel = new QueryParamsViewModel();

            //LogMessages = new ObservableCollection<ProcessLog> (EdhLogDataContext.NameStartsWithQuery("1000"));
        }
Exemplo n.º 3
0
        public override void CreateDatabase()
        {
            //writer = new StreamWriter("c:/Oracle.txt", false);
            var constr     = string.Format(string.Format("Data Source=vpc1;User ID={0};password={1}", "System", "test"));
            var xmlMapping = XmlMappingSource.FromStream(GetType().Assembly.GetManifestResourceStream("Test.Northwind.Oracle.Odp.map"));
            var database   = new OdpOracleNorthwind(constr, xmlMapping)
            {
                Log = Console.Out
            };                                                                              //new OdpOracleNorthwind(constr) { Log = Console.Out };//

            if (database.DatabaseExists())
            {
                database.DeleteDatabase();
            }
            try
            {
                database.CreateDatabase();
            }
            catch (Exception)
            {
                database.Log.Flush();
                database.Log.Close();
                throw;
            }
            finally
            {
                database.Dispose();
            }
        }
Exemplo n.º 4
0
        public void AttributeLicense1()
        {
            DataContext context;
            var         mapping = XmlMappingSource.FromXml(
                @"<Database Name=""Northwind"" Provider=""ALinq.Firebird.FirebirdProvider, ALinq.Firebird, Version=1.2.7.0, Culture=Neutral, PublicKeyToken=2b23f34316d38f3a"" xmlns=""http://schemas.microsoft.com/linqtosql/mapping/2007"">
</Database>
");

            context = new MyDataContext("", mapping);
            Assert.IsNotNull(((SqlProvider)context.Provider).License);
            var license = (ALinqLicenseProvider.LicFileLicense)((SqlProvider)context.Provider).License;

            Assert.IsFalse(license.IsTrial);

            mapping = XmlMappingSource.FromXml(
                @"<Database Name=""Northwind"" Provider=""ALinq.Access.AccessDbProvider, ALinq.Access, Version=1.7.9.0, Culture=neutral, PublicKeyToken=2b23f34316d38f3a"" xmlns=""http://schemas.microsoft.com/linqtosql/mapping/2007"">
</Database>
");
            context = new MyDataContext("", mapping);
            Assert.IsNotNull(((SqlProvider)context.Provider).License);
            license = (ALinqLicenseProvider.LicFileLicense)((SqlProvider)context.Provider).License;
            Assert.IsFalse(license.IsTrial);

            mapping = XmlMappingSource.FromXml(
                @"<Database Name=""Northwind"" Provider=""ALinq.SQLite.SQLiteProvider, ALinq.SQLite, Version=1.7.9.0, Culture=neutral, PublicKeyToken=2b23f34316d38f3a"" xmlns=""http://schemas.microsoft.com/linqtosql/mapping/2007"">
</Database>
");
            context = new MyDataContext("", mapping);
            Assert.IsNotNull(((SqlProvider)context.Provider).License);
            license = (ALinqLicenseProvider.LicFileLicense)((SqlProvider)context.Provider).License;
            Assert.IsFalse(license.IsTrial);
        }
Exemplo n.º 5
0
        //[TestMethod]
        public void TestTableMappingName()
        {
            var xmlMapping = XmlMappingSource.FromUrl("Northwind.Oracle.map");
            var model      = xmlMapping.GetModel(typeof(NorthwindDemo.NorthwindDatabase));
            var metaTable  = model.GetTable(typeof(NorthwindDemo.Contact));

            Assert.AreEqual("Contacts", metaTable.TableName);
        }
Exemplo n.º 6
0
        public DatabaseFixture()
        {
            var databaseConfigFileName = "AnalyticViewer.database.config";
            var installationDirectory  = @"c:\Dev\AnalyticsViewer\AvDataAccess";
            var databaseConfig         = System.IO.Path.Combine(installationDirectory, databaseConfigFileName);
            var mappingSource          = XmlMappingSource.FromUrl(databaseConfig);

            AvDataContext = new AvDataContext("Data Source=lonbscadsqlbl01;Initial Catalog=CADIS_E2E01;Integrated Security=True", mappingSource, false, 30);
        }
Exemplo n.º 7
0
        public override NorthwindDatabase CreateDataBaseInstace()
        {
            var xmlMapping = XmlMappingSource.FromStream(typeof(SQLiteTest).Assembly.GetManifestResourceStream("Test.Northwind.SQLite.map"));

            writer = Console.Out;
            return(new SQLiteNorthwind(DbFileName)
            {
                Log = writer
            });                                                     //xmlMapping
        }
Exemplo n.º 8
0
        public static ParkDataContext CreateParking(string connStr)
        {
            System.Diagnostics.Debug.Assert(!string.IsNullOrEmpty(connStr), "没有找到有效的数据库连接!");
            Stream          stream        = typeof(ParkDataContextFactory).Assembly.GetManifestResourceStream("Ralid.Park.DAL.LinqDataProvider.ParkingMapping.xml");
            MappingSource   mappingSource = XmlMappingSource.FromStream(stream);
            ParkDataContext parking       = new ParkDataContext(connStr, mappingSource);

            //parking.Log = System.Console.Out;
            return(parking);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="XmlMappingSourceManager"/> class.
        /// </summary>
        /// <param name="mappingStream">
        /// The mapping stream.
        /// </param>
        public XmlMappingSourceManager(Stream mappingStream)
        {
            using (MemoryStream memoryStream = ReadAllToMemoryStream(mappingStream))
            {
                this.NoAssociationsMappingSource = CreateNoAssociationsMappingSource(memoryStream);
                memoryStream.Position            = 0;

                this.MappingSource = XmlMappingSource.FromStream(memoryStream);
            }
        }
Exemplo n.º 10
0
        public override NorthwindDatabase CreateDataBaseInstace()
        {
            var xmlMapping = XmlMappingSource.FromStream(GetType().Assembly.GetManifestResourceStream("Test.Northwind.Oracle.Odp.map")); //XmlMappingSource.FromUrl("Northwind.Oracle.Odp.map");

            writer = Console.Out;
            return(new OdpOracleNorthwind("Data Source=vpc1;Persist Security Info=True;User ID=Northwind;Password=Test;", xmlMapping)
            {
                Log = writer
            });
        }
Exemplo n.º 11
0
        public override NorthwindDatabase CreateDataBaseInstace()
        {
            writer = Console.Out;
            var xmlMapping = XmlMappingSource.FromStream(GetType().Assembly.GetManifestResourceStream("Test.Northwind.MySql.map"));

            return(new MySqlNorthwind(CreateConnection().ConnectionString)
            {
                Log = writer
            });                                                                             //xmlMapping
        }
Exemplo n.º 12
0
        public void XmlMapping_7_2()
        {
            XmlMappingSource map = XmlMappingSource.FromXml(System.IO.File.ReadAllText(@"lia.xml"));

            using (DataContext dataContext =
                       new DataContext(ConfigurationManager.ConnectionStrings["SqlConStr"].ConnectionString, map))
            {
                var authors = dataContext.GetTable <AuthorXml>();
                ObjectDumper.Write(authors);
            }
        }
Exemplo n.º 13
0
        public void TestInitialize()
        {
            var xmlMapping = XmlMappingSource.FromStream(typeof(SQLiteTest).Assembly.GetManifestResourceStream("Test.Northwind.Access.map"));

            //db = new AccessNorthwind("C:/Northwind.mdb");
            //db = new AccessNorthwind("C:/Northwind.mdb", xmlMapping);
            //db = new SQLiteNorthwind("C:/Northwind.db3");

            db     = new MySqlNorthwind(MySqlNorthwind.CreateConnection("root", "test", "Northwind", "localhost", 3306).ConnectionString);
            db.Log = Console.Out;
        }
Exemplo n.º 14
0
        public override NorthwindDemo.NorthwindDatabase CreateDataBaseInstace()
        {
            var writer = Console.Out;
            //var xmlMapping = XmlMappingSource.FromUrl("Northwind.Firebird.map");
            var xmlMapping = XmlMappingSource.FromStream(GetType().Assembly.GetManifestResourceStream("Test.Northwind.Firebird.map"));

            //return new FirebirdNorthwind("C:/Northwind.FDB") { Log = writer };
            return(new FirebirdNorthwind("User=SYSDBA;Password=masterkey;Database=Northwind;DataSource=localhost;ServerType=0")
            {
                Log = writer
            });
        }
Exemplo n.º 15
0
        public virtual void RegisterInstances()
        {
            AppConfiguration = Container.Resolve <IAppConfiguration>();
            var connectionString = AppConfiguration.DatabaseConnection;

            var mappingSource = XmlMappingSource.FromUrl(AppConfiguration.DatabaseConfigFilename);
            var timeout       = AppConfiguration.DatabaseTimeout;

            repository = new AvDataContext(connectionString, mappingSource, false, timeout);

            Container.RegisterInstance <IUnitOfWork>(repository);
        }
Exemplo n.º 16
0
        public static XmlMappingSource GetMapping()
        {
            if (_Mapping == null)
            {
                using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("HL.DomainModel.DataMapping.OperationalMap.xml"))
                {
                    _Mapping = XmlMappingSource.FromStream(stream);
                }
            }

            return(_Mapping);
        }
        /// <summary>
        /// Gets mapping to initialize Linq2Sql data context.
        /// </summary>
        /// <remarks>
        /// Fixture expects the linq2sql implementation contains one and only embedded resource file
        /// with mapping configuration.
        /// </remarks>
        protected virtual MappingSource GetMapping()
        {
            var executingAssembly = Assembly.GetAssembly(typeof(CustomerRepository));

            var customerMappingFileName =
                (from r in executingAssembly.GetManifestResourceNames().AsEnumerable()
                 where r.EndsWith(".linq2sql.xml")
                 select r).Single();

            var customerMappingFile = executingAssembly.GetManifestResourceStream(customerMappingFileName);

            return(XmlMappingSource.FromStream(customerMappingFile));
        }
Exemplo n.º 18
0
        public override NorthwindDatabase CreateDataBaseInstace()
        {
            var xmlMapping = XmlMappingSource.FromUrl("Northwind.SQL2000.map");

            writer = Console.Out;
            var constr  = @"Data Source=vpc1\SQLEXPRESS;Initial Catalog=Northwind;User ID=sa;PASSWORD=test";
            var builder = new SqlConnectionStringBuilder(constr);

            return(new Sql2000Northwind(new SqlConnection(builder.ToString()))
            {
                Log = writer
            });                                                                                 //, xmlMapping
        }
Exemplo n.º 19
0
 public DatabaseFixture()
 {
     if (UseFakeContext)
     {
         EdhLogDataContext = new EdhLogFakeDataContext();
     }
     else
     {
         var databaseConfigFileName = "EdhLogViewer.database.config";
         var installationDirectory  = @"c:\Dev\EdhLogViewer\DataAccess";
         var databaseConfig         = System.IO.Path.Combine(installationDirectory, databaseConfigFileName);
         var mappingSource          = XmlMappingSource.FromUrl(databaseConfig);
         EdhLogDataContext = new EdhLogDataContext("Data Source=EDHDBSIT01,65000;Initial Catalog=ODS_SIT01;Integrated Security=True", mappingSource, false, 30);
     }
 }
Exemplo n.º 20
0
        private AdventureWorks2008DataContext GetContext()
        {
            if (_mappingSourceFromXmlFile == null)
            {
                var modelAssembly  = typeof(AdventureWorks2008DataContext).Assembly;
                var resourceStream = modelAssembly.GetManifestResourceStream("AdventureWorks2008.AdventureWorks2008Mappings.xml");
                _mappingSourceFromXmlFile = XmlMappingSource.FromStream(resourceStream);
            }
            // pass in sql connection to make sure the profiler gathers the right information
            var factory    = DbProviderFactories.GetFactory("System.Data.SqlClient");
            var connection = factory.CreateConnection();

            connection.ConnectionString = ConfigurationManager.ConnectionStrings["AdventureWorksConnectionString.SQL Server (SqlClient)"].ConnectionString;
            return(new AdventureWorks2008DataContext(connection, _mappingSourceFromXmlFile));
        }
Exemplo n.º 21
0
        public override DataMapper CreateDataMapper()
        {
            if (mappingSource == null)
            {
                var mapping = Assembly.GetExecutingAssembly().GetManifestResourceStream(
                    "NailsFramework.Tests.Persistence.LinqToSql.TestModel.Mappings.xml");
                mappingSource = XmlMappingSource.FromStream(mapping);
                mapping.Dispose();
            }

            var linq2Sql = new NailsFramework.Persistence.LinqToSql
            {
                MappingSource = mappingSource
            };

            return(linq2Sql);
        }
Exemplo n.º 22
0
        /// <summary>
        /// 1) SQLMetal /Server:(localdb)\MSSQLLocalDB /Database:BookLibrary /Namespace:LinqToSqlMetal /Code:BookLibrary.CS /Map:BookLibrary.XML /Pluralize /Functions /Sprocs /Views
        ///     this command generate sqlmetal files to work with database it has all required syntaxes and create according to it
        ///     for more :  http://msdn2.microsoft.com/en-us/library/bb386987.aspx.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            string connectionString = @"Data Source=(localdb)\mssqllocaldb;Initial Catalog=BookLibrary;Integrated Security=True";
            //Creating xml mapping
            XmlMappingSource mappingSource = XmlMappingSource.FromUrl(@"C:\Users\Sumitkiran.Gaurav\source\repos\LinqToSqlMetal\LinqToSqlMetal\BookLibrary.XML");

            // creating datacontext
            BookLibrary bookLibraryContext = new BookLibrary(connectionString, mappingSource);

            IEnumerable <Bookdata> result = from book in bookLibraryContext.Bookdatas
                                            where book.Title.Contains("India")
                                            select book;

            foreach (Bookdata book in result)
            {
                Console.WriteLine(book);
            }
        }
Exemplo n.º 23
0
        public void GetCreateTableCommandTest()
        {
            LicenseManager.CurrentContext.SetSavedLicenseKey(typeof(ALinq.Access.AccessDbProvider), "ansiboy" + Environment.NewLine + "QO77626437CFA2FE9E");
            //var obj = LicenseManager.CreateWithContext(typeof (ALinq.Access.AccessDbProvider), new LicenseContext());
            //Console.Write(obj);
            var mapping = XmlMappingSource.FromStream(GetType().Assembly.GetManifestResourceStream("Test.Northwind.Access.map"));
            var db      = new AccessNorthwind("c:/nrothwind.mdb", mapping);

            var target = new DatabaseSqlBuilder((SqlProvider)db.Provider);

            MetaTable table = db.Mapping.GetTable(typeof(Category));
            //string expected = string.Empty;
            string actual;

            actual = target.GetCreateTableCommand(table);
            //Assert.AreEqual(expected, actual);
            //Assert.Inconclusive("Verify the correctness of this test method.");
            Console.WriteLine(actual);
        }
Exemplo n.º 24
0
        public static void Initialize(TestContext testContext)
        {
            //var type = typeof(SQLiteTest);
            //var path = type.Module.FullyQualifiedName;
            //var filePath = Path.GetDirectoryName(path) + @"\ALinq.SQLite.lic";
            //File.Copy(@"E:\ALinqs\ALinq1.8\Test\ALinq.SQLite.lic", filePath);

            var xmlMapping = XmlMappingSource.FromStream(typeof(SQLiteTest).Assembly.GetManifestResourceStream("Test.Northwind.SQLite.map"));

            writer = new StreamWriter(LogFileName, false);
            var database = new SQLiteNorthwind(DbFileName)
            {
                Log = writer
            };                                                              //, xmlMapping

            if (!database.DatabaseExists())
            {
                database.CreateDatabase();
                database.Connection.Close();
            }
        }
        public static AttendanceDataContext Createattendance(string connStr)
        {
            System.Diagnostics.Debug.Assert(!string.IsNullOrEmpty(connStr), "没有找到有效的数据库连接!");
            IDbConnection    connection    = null;
            Stream           stream        = typeof(AttendanceDataContextFactory).Assembly.GetManifestResourceStream("LJH.Attendance.DAL.LinqDataProvider.DataMapping.xml");
            XmlMappingSource mappingSource = XmlMappingSource.FromStream(stream);
            string           sqlType       = AppSettings.CurrentSetting.GetSQLType();

            if (sqlType == "MSSQL")
            {
                connection = new SqlConnection(AppSettings.CurrentSetting.GetConnectString());
            }
            else if (sqlType == "SQLITE")
            {
                connection = new SQLiteConnection(AppSettings.CurrentSetting.GetConnectString());
            }
            System.Diagnostics.Debug.Assert(connection != null, "没有找到有效的数据库连接!");
            AttendanceDataContext attendance = new AttendanceDataContext(connection, mappingSource);

            //attendance.Log = System.Console.Out;
            return(attendance);
        }
Exemplo n.º 26
0
        protected virtual MappingSource AdaptMappingSource(Type dataContextType)
        {
            MappingSource adaptedMappingSource;

            if (dataContextType == null)
            {
                throw new ArgumentNullException("dataContextType");
            }

            if (!AdaptedMappingSources.TryGetValue(dataContextType, out adaptedMappingSource))
            {
                adaptedMappingSource = XmlMappingSource
                                       .FromXml(UnderlyingMappingSource
                                                .GetModel(dataContextType)
                                                .Adapt(ModelAdapter)
                                                .ToString());

                AdaptedMappingSources.Add(dataContextType, adaptedMappingSource);
            }

            return(adaptedMappingSource);
        }
Exemplo n.º 27
0
        /// <summary>
        /// Creates the mapping source with no associations in mapping.
        /// </summary>
        /// <param name="mappingStream">
        /// The mapping stream.
        /// </param>
        /// <returns>
        /// The mapping source with no associations
        /// </returns>
        private static MappingSource CreateNoAssociationsMappingSource(Stream mappingStream)
        {
            var stripAssociationsTransform = new XslCompiledTransform();

            Stream sheetStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("LogicSoftware.DataAccess.Repository.Mapping.StripAssociations.xslt");

            using (XmlReader sheetReader = XmlReader.Create(sheetStream))
            {
                stripAssociationsTransform.Load(sheetReader);
            }

            using (var buffer = new MemoryStream())
            {
                using (XmlReader mappingReader = XmlReader.Create(mappingStream))
                {
                    stripAssociationsTransform.Transform(mappingReader, new XsltArgumentList(), buffer);
                }

                buffer.Position = 0;

                return(XmlMappingSource.FromStream(buffer));
            }
        }
Exemplo n.º 28
0
        public void Load_LinqToSql_container()
        {
            const string l2sConnectionStringName =
                "Ignorance.Testing.Properties.Settings.AdventureWorksConnectionString";
            string l2sConnectionString =
                ConfigurationManager.ConnectionStrings[l2sConnectionStringName].ConnectionString;

            // get the map
            var map = XmlMappingSource.FromXml(Properties.Resources.AdventureWorks);

            var container = new UnityContainer()
                            .RegisterType <AdventureWorks>(
                new InjectionConstructor(l2sConnectionString, map))
                            .RegisterType <IWork, Ignorance.LinqToSql.Work>(
                new InjectionConstructor(typeof(AdventureWorks)))
                            .RegisterType(typeof(IStore <Department>),
                                          typeof(Ignorance.Testing.Data.LinqToSql.DepartmentStore))
                            .RegisterType(typeof(IStore <>), typeof(Ignorance.LinqToSql.Store <>));

            Create.Container = (UnityContainer)container;

            Assert.IsTrue(true, "Failed to load the LINQ to SQL IoC Container.");
        }
Exemplo n.º 29
0
        private static MappingSource GetMapping()
        {
            var mapping = XmlMappingSource.FromStream(typeof(EfzNorthwind).Assembly.GetManifestResourceStream("NorthwindDemo.Northwind.Efz.map"));

            return(mapping);
        }
Exemplo n.º 30
0
 public SQLiteNorthwind(string conn, XmlMappingSource mapping)
     : base(conn, mapping)
 {
 }