Beispiel #1
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);
        }
Beispiel #2
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);
            }
        }
Beispiel #3
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);
        }
Beispiel #4
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.");
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            XmlMappingSource xms = XmlMappingSource.FromXml(File.ReadAllText("Test.map"));

            Test context = new Test(connString, xms);

            // 单表查询
            var query =
                from testMain in context.Test_main
                select testMain;

            foreach (Test_main main in query)
            {
                Console.WriteLine("Main[{0}, {1}]", main.Id, main.Value);
            }

            // 关联查询
            var query2 =
                from testSub in context.Test_sub
                where testSub.Test_main.Value == "ONE"
                select testSub;

            foreach (Test_sub sub in query2)
            {
                Console.WriteLine("Sub[{0}, {1}]", sub.Id, sub.Value);
            }

            // 插入.
            Test_main main3 = new Test_main();

            main3.Id    = 3;
            main3.Value = "Three";
            context.Test_main.InsertOnSubmit(main3);
            context.SubmitChanges();

            Console.WriteLine("INSERT FINISH!");
            Console.ReadLine();

            // 更新.
            var newTestMain =
                (from testMain in context.Test_main
                 where testMain.Id == 3
                 select testMain).First();

            newTestMain.Value = "Three3";
            context.SubmitChanges();

            Console.WriteLine("UPDATE FINISH!");
            Console.ReadLine();


            // 单表查询 TOP 2
            var queryTop2 =
                (from testMain in context.Test_main
                 orderby testMain.Id descending
                 select testMain).Take(2);

            foreach (Test_main main in queryTop2)
            {
                Console.WriteLine("Main[{0}, {1}]", main.Id, main.Value);
            }

            // 删除.
            context.Test_main.DeleteOnSubmit(newTestMain);
            context.SubmitChanges();

            Console.WriteLine("DELETE FINISH!");
            Console.ReadLine();
        }
Beispiel #6
0
 /// <summary>
 /// Creates an XmlMappingSource generated from the fluent mapping information
 /// </summary>
 /// <returns>An XmlMappingSource object</returns>
 public virtual MappingSource CreateMappingSource()
 {
     return(XmlMappingSource.FromXml(CreateDocument().ToString()));
 }