mono /mcs/class/System.Data.Linq/src/DbLinq/Test/Providers/Linq_101_Samples/Object Loading.cs

Language C# Lines 175
MD5 Hash 580484bf0f66f935f07ad7c3e4f617f1 Estimated Cost $3,326 (why?)
Repository https://bitbucket.org/danipen/mono.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Test_NUnit;
using NUnit.Framework;
using Test_NUnit.Linq_101_Samples;

#if MONO_STRICT
using System.Data.Linq;
#else
using DbLinq.Data.Linq;
#endif

using nwind;

// test ns Linq_101_Samples
#if MYSQL
    namespace Test_NUnit_MySql.Linq_101_Samples
#elif ORACLE && ODP
    namespace Test_NUnit_OracleODP.Linq_101_Samples
#elif ORACLE
    namespace Test_NUnit_Oracle.Linq_101_Samples
#elif POSTGRES
    namespace Test_NUnit_PostgreSql.Linq_101_Samples
#elif SQLITE
    namespace Test_NUnit_Sqlite.Linq_101_Samples
#elif INGRES
    namespace Test_NUnit_Ingres.Linq_101_Samples
#elif MSSQL && MONO_STRICT
    namespace Test_NUnit_MsSql_Strict.Linq_101_Samples
#elif MSSQL
    namespace Test_NUnit_MsSql.Linq_101_Samples
#elif FIREBIRD
    namespace Test_NUnit_Firebird.Linq_101_Samples
#endif
{
    [TestFixture]
    public class Object_Loading : TestBase
    {
        [Test(Description = "This sample demonstrates how to use Including to request related data during the original query so that additional roundtrips to the database are not required later when navigating through the retrieved objects.")]
        public void LinqToSqlObject01()
        {
            Northwind db = CreateDB();

            var custs = from c in db.Customers
                        where c.City == "Marseille"
                        select c;

            foreach (var cust in custs)
                foreach (var ord in cust.Orders)
                {
                    Console.WriteLine("CustomerID {0} has an OrderID {1}.", cust.CustomerID, ord.OrderID);
                }

            var list = custs.ToList();
            Assert.IsTrue(list.Count > 0);

        }

#if !DEBUG && (SQLITE || POSTGRES || (MSSQL && !MONO_STRICT))
        [Explicit]
#endif
        [Linq101SamplesModified("The original sample didn't compile, db2 Northwind context was used for nothing")]
        [Test(Description = "This sample demonstrates how to use Including to request related data during the original query so that additional roundtrips to the database are not required later when navigating through the retrieved objects.")]
        public void LinqToSqlObject02()
        {
            Northwind db = CreateDB();


            var ds = new DataLoadOptions();
            ds.LoadWith<Customer>(p => p.Orders);

            db.LoadOptions = ds;

            var custs = from c in db.Customers
                        where c.City == "Marseille"
                        select c;

            foreach (var cust in custs)
                foreach (var ord in cust.Orders)
                    Console.WriteLine("CustomerID {0} has an OrderID {1}.", cust.CustomerID, ord.OrderID);

            var list = custs.ToList();
            Assert.IsTrue(list.Count > 0);
        }

        [Test(Description = "This sample demonstrates how navigating through relationships in retrieved objects can end up triggering new queries to the database if the data was not requested by the original query.")]
        public void LinqToSqlObject03()
        {
            Northwind db = CreateDB();

            var custs = from c in db.Customers
                        where c.City == "London"
                        select c;

            foreach (var cust in custs)
                foreach (var ord in cust.Orders)
                    foreach (var orderDetail in ord.OrderDetails)
                    {
                        Console.WriteLine("CustomerID {0} has an OrderID {1} with ProductID {2} that has name {3}.",
                            cust.CustomerID, ord.OrderID, orderDetail.ProductID, orderDetail.Product.ProductName);
                    }

            var list = custs.ToList();
            Assert.IsTrue(list.Count > 0);

        }

#if !DEBUG && (SQLITE || POSTGRES || (MSSQL && !MONO_STRICT))
        [Explicit]
#endif
        [Linq101SamplesModified("The original sample didn't compile, db2 Northwind context was used for nothing")]
        [Test(Description = "This sample demonstrates how to use Including to request related data during the original query so that additional roundtrips to the database are not required later when navigating through the retrieved objects.")]
        public void LinqToSqlObject04()
        {
            var db = CreateDB();

            var ds = new DataLoadOptions();
            ds.LoadWith<Customer>(p => p.Orders);
            ds.LoadWith<Order>(p => p.OrderDetails);

            db.LoadOptions = ds;

            var custs = from c in db.Customers
                        where c.City == "London"
                        select c;

            foreach (var cust in custs)
                foreach (var ord in cust.Orders)
                    foreach (var orderDetail in ord.OrderDetails)
                    {
                        Console.WriteLine("CustomerID {0} has an OrderID {1} with ProductID {2} that has name {3}.",
                            cust.CustomerID, ord.OrderID, orderDetail.ProductID, orderDetail.Product.ProductName);
                    }

            var list = custs.ToList();
            Assert.IsTrue(list.Count > 0);


        }

        [Test(Description = "This sample demonstrates how navigating through relationships in retrieved objects can result in triggering new queries to the database if the data was not requested by the original query.")]
        public void LinqToSqlObject05()
        {
            var db = CreateDB();

            var emps = from e in db.Employees select e;

            foreach (var emp in emps)
                foreach (var man in emp.Employees)
                    Console.WriteLine("Employee {0} reported to Manager {1}.", emp.FirstName, man.FirstName);

            var list = emps.ToList();
            Assert.IsTrue(list.Count > 0);
        }



        [Test(Description = "This sample demonstrates how navigating through Link in retrieved objects can end up triggering new queries to the database if the data type is Link.")]
        public void LinqToSqlObject06()
        {
            var db = CreateDB();

            var emps = from c in db.Employees select c;

            foreach (var emp in emps)
                Console.WriteLine("{0}", emp.Notes);

            var list = emps.ToList();
            Assert.IsTrue(list.Count > 0);
        }
    }
}
Back to Top