Beispiel #1
0
        public void TestIdentityColumn()
        {
            using (var ctx = CreateAdventureWorksContext())
            {
                var ms = LinqToDBForEFTools.GetMappingSchema(ctx.Model);

                var identity = ms.GetAttribute <ColumnAttribute>(typeof(SalesOrderDetail),
                                                                 MemberHelper.MemberOf <SalesOrderDetail>(c => c.SalesOrderDetailID));

                Assert.NotNull(identity);
                Assert.AreEqual(true, identity.IsIdentity);
            }
        }
Beispiel #2
0
        public void TestStringMappings()
        {
            using (var db = CreateContext())
            {
                var ms = LinqToDBForEFTools.GetMappingSchema(db.Model, db);
                var ed = ms.GetEntityDescriptor(typeof(StringTypes));

                ed.Columns.First(c => c.MemberName == nameof(StringTypes.AnsiString)).DataType.Should()
                .Be(DataType.VarChar);

                ed.Columns.First(c => c.MemberName == nameof(StringTypes.UnicodeString)).DataType.Should()
                .Be(DataType.NVarChar);
            }
        }
Beispiel #3
0
        public void TestAssociations()
        {
            using (var ctx = CreateContext(false))
            {
                var ms = LinqToDBForEFTools.GetMappingSchema(ctx.Model, ctx);

                var associationOrder = ms.GetAttribute <AssociationAttribute>(typeof(Customer),
                                                                              MemberHelper.MemberOf <Customer>(c => c.Orders));

                Assert.NotNull(associationOrder);
                Assert.That(associationOrder !.ThisKey, Is.EqualTo("CustomerId"));
                Assert.That(associationOrder.OtherKey, Is.EqualTo("CustomerId"));
            }
        }
Beispiel #4
0
        public void TestKey()
        {
            using (var ctx = CreateContext(false))
            {
                var ms = LinqToDBForEFTools.GetMappingSchema(ctx.Model, ctx);

                var customerPk = ms.GetAttribute <ColumnAttribute>(typeof(Customer),
                                                                   MemberHelper.MemberOf <Customer>(c => c.CustomerId));

                Assert.NotNull(customerPk);
                Assert.AreEqual(true, customerPk !.IsPrimaryKey);
                Assert.AreEqual(0, customerPk.PrimaryKeyOrder);
            }
        }
        public void TestIdentityColumn()
        {
            using (var ctx = CreateContext())
            {
                var dependencies  = ctx.GetService <RelationalSqlTranslatingExpressionVisitorDependencies>();
                var mappingSource = ctx.GetService <IRelationalTypeMappingSource>();
                var converters    = ctx.GetService <IValueConverterSelector>();
                var ms            = LinqToDBForEFTools.GetMappingSchema(ctx.Model, converters, dependencies, mappingSource);

                var identity = ms.GetAttribute <ColumnAttribute>(typeof(Customer),
                                                                 MemberHelper.MemberOf <Customer>(c => c.CustomerId));

                //TODO:
                //Assert.NotNull(identity);
                //Assert.AreEqual(true, identity.IsIdentity);
            }
        }
        public void TestAssociations()
        {
            using (var ctx = CreateContext())
            {
                var dependencies  = ctx.GetService <RelationalSqlTranslatingExpressionVisitorDependencies>();
                var mappingSource = ctx.GetService <IRelationalTypeMappingSource>();
                var converters    = ctx.GetService <IValueConverterSelector>();
                var ms            = LinqToDBForEFTools.GetMappingSchema(ctx.Model, converters, dependencies, null);

                var associationOrder = ms.GetAttribute <AssociationAttribute>(typeof(Customer),
                                                                              MemberHelper.MemberOf <Customer>(c => c.Orders));

                Assert.NotNull(associationOrder);
                Assert.That(associationOrder.ThisKey, Is.EqualTo("CustomerId"));
                Assert.That(associationOrder.OtherKey, Is.EqualTo("CustomerId"));
            }
        }
Beispiel #7
0
        public void TestKey()
        {
            using (var ctx = CreateContext(false))
            {
                var dependencies  = ctx.GetService <RelationalSqlTranslatingExpressionVisitorDependencies>();
                var mappingSource = ctx.GetService <IRelationalTypeMappingSource>();
                var converters    = ctx.GetService <IValueConverterSelector>();
                var ms            = LinqToDBForEFTools.GetMappingSchema(ctx.Model, converters, dependencies, mappingSource);

                var customerPk = ms.GetAttribute <ColumnAttribute>(typeof(Customer),
                                                                   MemberHelper.MemberOf <Customer>(c => c.CustomerId));

                Assert.NotNull(customerPk);
                Assert.AreEqual(true, customerPk.IsPrimaryKey);
                Assert.AreEqual(0, customerPk.PrimaryKeyOrder);
            }
        }
Beispiel #8
0
        public void TestAssociations()
        {
            using (var ctx = CreateAdventureWorksContext())
            {
                var ms = LinqToDBForEFTools.GetMappingSchema(ctx.Model);

                var associationCustomer = ms.GetAttribute <AssociationAttribute>(typeof(CustomerAddress),
                                                                                 MemberHelper.MemberOf <CustomerAddress>(c => c.Customer));

                Assert.NotNull(associationCustomer);
                Assert.AreEqual("CustomerID", associationCustomer.ThisKey);
                Assert.AreEqual("CustomerID", associationCustomer.OtherKey);

                var associationAddress = ms.GetAttribute <AssociationAttribute>(typeof(CustomerAddress),
                                                                                MemberHelper.MemberOf <CustomerAddress>(c => c.Address));

                Assert.NotNull(associationAddress);
                Assert.AreEqual("AddressID", associationAddress.ThisKey);
                Assert.AreEqual("AddressID", associationAddress.OtherKey);
            }
        }
Beispiel #9
0
        public void TestCompositeKey()
        {
            using (var ctx = CreateAdventureWorksContext())
            {
                var ms = LinqToDBForEFTools.GetMappingSchema(ctx.Model);

                var customerPk = ms.GetAttribute <ColumnAttribute>(typeof(CustomerAddress),
                                                                   MemberHelper.MemberOf <CustomerAddress>(c => c.CustomerID));

                Assert.NotNull(customerPk);
                Assert.AreEqual(true, customerPk.IsPrimaryKey);
                Assert.AreEqual(0, customerPk.PrimaryKeyOrder);

                var addressPk = ms.GetAttribute <ColumnAttribute>(typeof(CustomerAddress),
                                                                  MemberHelper.MemberOf <CustomerAddress>(c => c.AddressID));

                Assert.NotNull(addressPk);
                Assert.AreEqual(true, addressPk.IsPrimaryKey);
                Assert.AreEqual(1, addressPk.PrimaryKeyOrder);
            }
        }