protected override IList<MappingConfiguration> PrepareMapping()
        {
            List<MappingConfiguration> configurations = new List<MappingConfiguration>();

            MappingConfiguration<Report> reportConfiguration = new MappingConfiguration<Report>();

            reportConfiguration.MapType(x => new
            {
                ID = x.Id,
                Name = x.Name,
                Duration = x.Duration,
                Destination = x.Destination,
                ClientsCount = x.ClientsCount,
                TotalIncome = x.TotalIncome,
                TransportCompany = x.TransportCompany,
                TransportType = x.TransportType,
                GuideName = x.GuideName,
                ExpenseId = x.ExpenseId
            }).ToTable("Reports");

            reportConfiguration.HasProperty(p => p.Id).IsIdentity(KeyGenerator.Autoinc);

            configurations.Add(reportConfiguration);

            return configurations;
        }
Esempio n. 2
0
        protected override void TestFixtureSetUp()
        {
            base.TestFixtureSetUp();
            _session = Session;
            _session.CreateKeyspace(_uniqueKsName);
            _session.ChangeKeyspace(_uniqueKsName);

            // Create necessary tables
            MappingConfiguration config1 = new MappingConfiguration();
            config1.MapperFactory.PocoDataFactory.AddDefinitionDefault(typeof(EntityWithTimeUuid),
                () => LinqAttributeBasedTypeDefinition.DetermineAttributes(typeof(EntityWithTimeUuid)));
            _tableEntityWithTimeUuid = new Table<EntityWithTimeUuid>(_session, config1);
            _tableEntityWithTimeUuid.Create();

            MappingConfiguration config2 = new MappingConfiguration();
            config2.MapperFactory.PocoDataFactory.AddDefinitionDefault(typeof(EntityWithNullableTimeUuid),
                () => LinqAttributeBasedTypeDefinition.DetermineAttributes(typeof(EntityWithNullableTimeUuid)));
            _tableEntityWithNullableTimeUuid = new Table<EntityWithNullableTimeUuid>(_session, config2);
            _tableEntityWithNullableTimeUuid.Create();

            _expectedTimeUuidObjectList = EntityWithTimeUuid.GetDefaultObjectList();
            _expectedNullableTimeUuidObjectList = EntityWithNullableTimeUuid.GetDefaultObjectList();

            _dateBefore = DateTimeOffset.Parse("2014-2-1");
            _dateAfter = DateTimeOffset.Parse("2014-4-1");
        }
		public MappingConfiguration<RentalRate> GetRentalRateClassConfiguration()
		{
			MappingConfiguration<RentalRate> configuration = new MappingConfiguration<RentalRate>();
			configuration.MapType(x => new { }).WithConcurencyControl(OptimisticConcurrencyControlStrategy.Changed).ToTable("RentalRates");
		
			return configuration;
		}
		private void ParseMappings(XPathNavigator navigator)
		{
			XPathNodeIterator xpni = navigator.Select(CfgXmlHelper.SessionFactoryMappingsExpression);
			while (xpni.MoveNext())
			{
				MappingConfiguration mc = new MappingConfiguration(xpni.Current);
				if (!mc.IsEmpty())
				{
					// Workaround add first an assembly&resource and then only the same assembly. 
					// the <mapping> of whole assembly is ignored (included only sigles resources)
					// The "ignore" log, is enough ?
					// Perhaps we can add some intelligence to remove single resource reference when a whole assembly is referenced
					//if (!mappings.Contains(mc))
					//{
					//  mappings.Add(mc);
					//}
					//else
					//{
					//  string logMessage = "Ignored mapping -> " + mc.ToString();
					//  if (log.IsDebugEnabled)
					//    log.Debug(logMessage);
					//  if (log.IsWarnEnabled)
					//    log.Warn(logMessage);
					//}

					// The control to prevent mappings duplication was removed since the engine do the right thing 
					// for this issue (simple is better)
					mappings.Add(mc);
				}
			}
		}
Esempio n. 5
0
        protected override void TestFixtureSetUp()
        {
            base.TestFixtureSetUp();
            _session = Session;
            _session.CreateKeyspace(_uniqueKsName);
            _session.ChangeKeyspace(_uniqueKsName);

            // Create necessary tables
            MappingConfiguration config1 = new MappingConfiguration();
            config1.MapperFactory.PocoDataFactory.AddDefinitionDefault(typeof (EntityWithTimeUuid),
                () => LinqAttributeBasedTypeDefinition.DetermineAttributes(typeof (EntityWithTimeUuid)));
            _tableEntityWithTimeUuid = new Table<EntityWithTimeUuid>(_session, config1);
            _tableEntityWithTimeUuid.Create();

            MappingConfiguration config2 = new MappingConfiguration();
            config2.MapperFactory.PocoDataFactory.AddDefinitionDefault(typeof (EntityWithNullableTimeUuid),
                () => LinqAttributeBasedTypeDefinition.DetermineAttributes(typeof (EntityWithNullableTimeUuid)));
            _tableEntityWithNullableTimeUuid = new Table<EntityWithNullableTimeUuid>(_session, config2);
            _tableEntityWithNullableTimeUuid.Create();

            _expectedTimeUuidObjectList = EntityWithTimeUuid.GetDefaultObjectList();
            for (int i=0; i<_expectedTimeUuidObjectList.Count; i++)
            {
                _expectedTimeUuidObjectList[i].StringType = i.ToString();
            }
        }
Esempio n. 6
0
 /// <summary>
 /// Maps the ProjectItemUrlData class
 /// </summary>
 /// <param name="mappings">The LocatoinItemUrlData class mappings.</param>
 private void MapUrlData(IList<MappingConfiguration> mappings)
 {
     // map the Url data type
     var urlDataMapping = new MappingConfiguration<ProjectItemUrlData>();
     urlDataMapping.MapType(p => new { }).Inheritance(InheritanceStrategy.Flat).ToTable("sf_url_data");
     mappings.Add(urlDataMapping);
 }
        private MappingConfiguration TeamMapping()
        {
            var mapping = new MappingConfiguration<Team>();

            mapping.MapType()
                   .ToTable("Team");

            mapping.HasProperty(m => m.Id)
                   .IsIdentity(KeyGenerator.Autoinc);

            mapping.HasProperty(m => m.IsOpen)
                   .HasColumnType("bit");

            mapping.HasAssociation(m => m.Owner)
                   .IsManaged()
                   .ToColumn("OwnerId");

            mapping.HasAssociation(m => m.Things)
                   .IsManaged()
                   .ToColumn("TeamId");

            mapping.HasAssociation(m => m.Members)
                   .WithOpposite(t => t.Team)
                   .IsManaged()
                   .IsDependent()
                   .ToColumn("TeamId");

            return mapping;
        }
Esempio n. 8
0
 public void PrepareDataAccessIncomePropertyConfigurations(MappingConfiguration<DataAccessIncome> configuration)
 {
     configuration.HasProperty(x => x.Id)
                  .IsIdentity(KeyGenerator.Autoinc)
                  .HasFieldName("id")
                  .WithDataAccessKind(DataAccessKind.ReadWrite)
                  .ToColumn("Id")
                  .IsNotNullable()
                  .HasColumnType("integer")
                  .HasPrecision(0)
                  .HasScale(0);
     configuration.HasProperty(x => x.DealerId)
                  .HasFieldName("dealerId")
                  .WithDataAccessKind(DataAccessKind.ReadWrite)
                  .ToColumn("DealerId")
                  .IsNotNullable()
                  .HasColumnType("integer")
                  .HasPrecision(0)
                  .HasScale(0);
     configuration.HasProperty(x => x.Date)
                  .HasFieldName("date")
                  .WithDataAccessKind(DataAccessKind.ReadWrite)
                  .ToColumn("Date")
                  .IsNotNullable()
                  .HasColumnType("datetime");
     configuration.HasProperty(x => x.Amount)
                  .HasFieldName("amount")
                  .WithDataAccessKind(DataAccessKind.ReadWrite)
                  .ToColumn("Amount")
                  .IsNotNullable()
                  .HasColumnType("decimal")
                  .HasPrecision(18)
                  .HasScale(2);
 }
        private MappingConfiguration<Question> CreateQuestionMapping()
        {
            MappingConfiguration<Question> questionMapping = new MappingConfiguration<Question>();
            questionMapping.MapType(question => new
            {
                QuestionId = question.Id,
                QueryText = question.QueryText,
                PostedById = question.PostedById
            })
            .ToTable("Questions");
            questionMapping.HasProperty(q => q.Id).IsIdentity();
            questionMapping.HasAssociation(q => q.PostedBy)
                .WithOpposite(u => u.CreatedQuestions)
                .HasConstraint((q, u) => q.PostedById == u.Id);
            questionMapping.HasAssociation(q => q.UsersThatVoted)
                .WithOpposite(u => u.VotedOnQuestions)
                .IsManaged()
                .MapJoinTable("QuestionsUsers", (q, u) => new 
                    {
                        QuestionGuid = q.Id,
                        UserGuid = u.Id
                    });
            questionMapping.HasAssociation(q => q.Answers)
                .WithOpposite(a => a.Question)
                .HasConstraint((q, a) => q.Id == a.QuestionId)
                .IsManaged();

            return questionMapping;
        }
 public void PrepareDataAccessCountryPropertyConfigurations(MappingConfiguration<DataAccessCountry> configuration)
 {
     configuration.HasProperty(x => x.Id)
                  .IsIdentity(KeyGenerator.Autoinc)
                  .HasFieldName("id")
                  .WithDataAccessKind(DataAccessKind.ReadWrite)
                  .ToColumn("Id")
                  .IsNotNullable()
                  .HasColumnType("integer")
                  .HasPrecision(0)
                  .HasScale(0);
     configuration.HasProperty(x => x.Name)
                  .HasFieldName("name")
                  .WithDataAccessKind(DataAccessKind.ReadWrite)
                  .ToColumn("Name")
                  .IsNullable()
                  .HasColumnType("longtext")
                  .HasLength(0);
     configuration.HasProperty(x => x.Region)
                  .HasFieldName("region")
                  .WithDataAccessKind(DataAccessKind.ReadWrite)
                  .ToColumn("Region")
                  .IsNotNullable()
                  .HasColumnType("integer")
                  .HasPrecision(0)
                  .HasScale(0);
 }
		public void PrepareTeamPropertyConfigurations(MappingConfiguration<Team> configuration)
		{
			configuration.HasProperty(x => x.TeamId).IsIdentity().HasFieldName("_teamId").WithDataAccessKind(DataAccessKind.ReadWrite);
			configuration.HasProperty(x => x.TeamMembers).HasFieldName("_teamMembers").WithDataAccessKind(DataAccessKind.ReadWrite);
			configuration.HasProperty(x => x.TeamName).HasFieldName("_teamName").WithDataAccessKind(DataAccessKind.ReadWrite);
			configuration.HasProperty(x => x.IsEnabled).HasFieldName("_isEnabled").WithDataAccessKind(DataAccessKind.ReadWrite);
		}
		public MappingConfiguration<TeamMember> GetTeamMemberClassConfiguration()
		{
			MappingConfiguration<TeamMember> configuration = new MappingConfiguration<TeamMember>();
			configuration.MapType().WithDataAccessKind(DataAccessKind.ReadWrite);
		
			return configuration;
		}
        protected override IList<MappingConfiguration> PrepareMapping()
        {
            List<MappingConfiguration> configurations = new List<MappingConfiguration>();

            var saleMapping = new MappingConfiguration<Sale>();
           saleMapping.MapType(sale => new
            {
                ID = sale.Id,
                Dish = sale.Dish,
                Quantity = sale.Quantity,
                Month = sale.Month,
                Year = sale.Year
            }).ToTable("Sale");
            saleMapping.HasProperty(s => s.Id).IsIdentity();

            configurations.Add(saleMapping);

            var dishReportMapping = new MappingConfiguration<DishReport>();
            dishReportMapping.MapType(report => new
            {
                Month = report.Month,
                DeliveredPrice = report.DeliveredPrice,
                SoldPrice = report.SoldPrice,
                Code = report.Code,
            }).ToTable("DishReport");
            saleMapping.HasProperty(s => s.Id).IsIdentity();

            configurations.Add(dishReportMapping);

            return configurations;
        }
Esempio n. 14
0
        public void CqlClient_Timestamp()
        {
            var config = new MappingConfiguration()
                .Define(new Map<Song>().PartitionKey(s => s.Id).TableName("song_insert"));

            //Use linq to create the table
            var table = new Table<Song>(_session, config);
            table.CreateIfNotExists();
            var mapper = new Mapper(_session, config);
            var song = new Song
            {
                Id = Guid.NewGuid(),
                Artist = "The Who",
                Title = "Substitute",
                ReleaseDate = DateTimeOffset.UtcNow
            };
            //Set timestamp to 1 day ago
            var timestamp = DateTimeOffset.Now.Subtract(TimeSpan.FromDays(1));
            mapper.Insert(song, true, CqlQueryOptions.New().SetTimestamp(timestamp));

            //query for timestamp in a column of the record
            var cqlLowerCasePartitionKey = "SELECT WRITETIME (Artist) AS timestamp FROM " + table.Name + " WHERE Id = " + song.Id + ";";
            var rows = _session.Execute(cqlLowerCasePartitionKey).GetRows().ToList();
            Assert.AreEqual(1, rows.Count);

            var creationTimestamp = rows[0].GetValue<long>("timestamp");
            Assert.NotNull(creationTimestamp);
            //Timestamp retrieved is in macroseconds. Converting it to milliseconds
            Assert.AreEqual(TypeSerializer.SinceUnixEpoch(timestamp).Ticks / 10, rows[0].GetValue<object>("timestamp"));
        }
		public void PreparePositionPropertyConfigurations(MappingConfiguration<Position> configuration) {
			configuration.HasProperty(x => x.Id).IsIdentity(KeyGenerator.Autoinc);
			configuration.HasProperty(x => x.HeaderId);
			configuration.HasProperty(x => x.Description);
			configuration.HasProperty(x => x.SequenceNumber);
			configuration.HasProperty(x => x.DateCreated);
			configuration.HasProperty(x => x.DateModified);
		}
		public void PrepareHeaderPropertyConfigurations(MappingConfiguration<Header> configuration) {
			configuration.HasProperty(x => x.Id);
			configuration.HasProperty(x => x.Title);
			configuration.HasProperty(x => x.IsChecked);
			configuration.HasProperty(x => x.Status);
			configuration.HasProperty(x => x.DateCreated);
			configuration.HasProperty(x => x.DateModified);
		}
		public void PrepareRentalRatePropertyConfigurations(MappingConfiguration<RentalRate> configuration)
		{
			configuration.HasProperty(x => x.RentalRateID).IsIdentity(KeyGenerator.Autoinc).HasFieldName("_rentalRateID").WithDataAccessKind(DataAccessKind.ReadWrite).ToColumn("RentalRateID").IsNotNullable().HasColumnType("int").HasPrecision(0).HasScale(0);
			configuration.HasProperty(x => x.CategoryID).HasFieldName("_categoryID").WithDataAccessKind(DataAccessKind.ReadWrite).ToColumn("CategoryID").IsNullable().HasColumnType("int").HasPrecision(0).HasScale(0);
			configuration.HasProperty(x => x.Daily).HasFieldName("_daily").WithDataAccessKind(DataAccessKind.ReadWrite).ToColumn("Daily").IsNullable().HasColumnType("smallmoney").HasPrecision(0).HasScale(0);
			configuration.HasProperty(x => x.Weekly).HasFieldName("_weekly").WithDataAccessKind(DataAccessKind.ReadWrite).ToColumn("Weekly").IsNullable().HasColumnType("smallmoney").HasPrecision(0).HasScale(0);
			configuration.HasProperty(x => x.Monthly).HasFieldName("_monthly").WithDataAccessKind(DataAccessKind.ReadWrite).ToColumn("Monthly").IsNullable().HasColumnType("smallmoney").HasPrecision(0).HasScale(0);
		}
 public void Table_Constructor_Uses_Provided_Mappings_With_Custom_TableName()
 {
     var config = new MappingConfiguration().Define(new Map<AllTypesEntity>().TableName("tbl4").Column(t => t.Int64Value, cm => cm.WithName("id1")));
     var table = new Table<AllTypesEntity>(null, config, "tbl_overridden1");
     Assert.AreEqual(
         @"SELECT BooleanValue, DateTimeValue, DecimalValue, DoubleValue, id1, IntValue, StringValue, UuidValue FROM tbl_overridden1 WHERE id1 = ?",
         table.Where(t => t.Int64Value == 1).ToString());
 }
        //artificial type for backing up online deletes and "executing" offline deletes
        private MappingConfiguration PrepareEntityDeleteConfig()
        {
            MappingConfiguration delEntityConfig = new MappingConfiguration(DeleteOperationDefinition.DeleteOperationTypeName, DeleteOperationDefinition.DeleteOperationTypeNamespace);
            delEntityConfig.HasArtificialPrimitiveProperty<int>(DeleteOperationDefinition.DeleteOperationId).IsIdentity(KeyGenerator.Autoinc).ToColumn(DeleteOperationDefinition.DeleteOperationId);
            delEntityConfig.HasArtificialPrimitiveProperty<int>(DeleteOperationDefinition.EntityToDeleteId).ToColumn(DeleteOperationDefinition.EntityToDeleteId);
            delEntityConfig.HasArtificialPrimitiveProperty<string>(DeleteOperationDefinition.EntityToDeleteType).ToColumn(DeleteOperationDefinition.EntityToDeleteType);

            return delEntityConfig;
        }
 public void PrepareDataAccessCountryAssociationConfigurations(MappingConfiguration<DataAccessCountry> configuration)
 {
     configuration.HasAssociation(x => x.DataAccessDealers)
                  .HasFieldName("dataAccessDealers")
                  .WithOpposite(x => x.DataAccessCountry)
                  .ToColumn("CountryId")
                  .HasConstraint((y, x) => x.CountryId == y.Id)
                  .WithDataAccessKind(DataAccessKind.ReadWrite);
 }
Esempio n. 21
0
        public MappingConfiguration<DataAccessIncome> GetDataAccessIncomeClassConfiguration()
        {
            MappingConfiguration<DataAccessIncome> configuration = new MappingConfiguration<DataAccessIncome>();
            configuration.MapType(x => new { })
                         .WithConcurencyControl(OptimisticConcurrencyControlStrategy.Changed)
                         .ToTable("incomes");

            return configuration;
        }
        public MappingConfiguration<JobSchedule> GetJobScheduleClassConfiguration()
        {
            var configuration = new MappingConfiguration<JobSchedule>();
            configuration.MapType(x => new { })
                         .WithConcurencyControl(Changed)
                         .ToTable("js_JobSchedules");

            return configuration;
        }
Esempio n. 23
0
 public void PrepareDataAccessIncomeAssociationConfigurations(MappingConfiguration<DataAccessIncome> configuration)
 {
     configuration.HasAssociation(x => x.DataAccessDealer)
                  .HasFieldName("dataAccessDealer")
                  .WithOpposite(x => x.DataAccessIncomes)
                  .ToColumn("DealerId")
                  .HasConstraint((x, y) => x.DealerId == y.Id)
                  .IsRequired()
                  .WithDataAccessKind(DataAccessKind.ReadWrite);
 }
 public void ConvertTypesUsing_Creates_Uses_MapperFactory_Instance()
 {
     var config = new MappingConfiguration();
     var originalMapperFactory = config.MapperFactory;
     //the mapper factory remains the same
     Assert.AreSame(originalMapperFactory, config.MapperFactory);
     config.ConvertTypesUsing(new DefaultTypeConverter());
     //New instance of the mapper factory
     Assert.AreNotSame(originalMapperFactory, config.MapperFactory);
 }
 public void Table_Constructor_Uses_Provided_Mappings()
 {
     var table = new Table<AllTypesEntity>(null);
     Assert.AreEqual(
         @"SELECT BooleanValue, DateTimeValue, DecimalValue, DoubleValue, Int64Value, IntValue, StringValue, UuidValue FROM AllTypesEntity",
         table.ToString());
     var config = new MappingConfiguration().Define(new Map<AllTypesEntity>().TableName("tbl3"));
     table = new Table<AllTypesEntity>(null, config);
     Assert.AreEqual(@"SELECT BooleanValue, DateTimeValue, DecimalValue, DoubleValue, Int64Value, IntValue, StringValue, UuidValue FROM tbl3",
         table.ToString());
 }
        private MappingConfiguration<IdentityRole> CreateIdentityRoleMapping()
        {
            MappingConfiguration<IdentityRole> identityRoleMapping = new MappingConfiguration<IdentityRole>();
            identityRoleMapping.MapType(role => new 
            {
                id = role.Id,
                Name = role.Name
            }).ToTable("IdentityRoles");
            identityRoleMapping.HasProperty(x => x.Id).IsIdentity();

            return identityRoleMapping;
        }
		private void ParseMappings(XPathNavigator navigator)
		{
			XPathNodeIterator xpni = navigator.Select(CfgXmlHelper.SessionFactoryMappingsExpression);
			while (xpni.MoveNext())
			{
				var mc = new MappingConfiguration(xpni.Current);
				if (!mc.IsEmpty())
				{
					Mappings.Add(mc);
				}
			}
		}
Esempio n. 28
0
        /// <summary>
        /// Maps the file data.
        /// </summary>
        /// <param name="mappings">The mappings.</param>
        private void MapFileData(List<MappingConfiguration> mappings)
        {
            var fileDataMapping = new MappingConfiguration<FileData>();

            fileDataMapping.MapType(p => new { }).WithConcurencyControl(OptimisticConcurrencyControlStrategy.None).ToTable("sf_files_monitor_data");
            fileDataMapping.HasProperty(p => p.Id).IsIdentity();
            fileDataMapping.HasProperty(p => p.FileName).ToColumn("file_name");
            fileDataMapping.HasProperty(p => p.FilePath).ToColumn("file_path");
            fileDataMapping.HasProperty(p => p.PackageName).ToColumn("package_name");

            mappings.Add(fileDataMapping);
        }
Esempio n. 29
0
        public void CqlClientConfiguration_UseIndividualMappingClassType_StaticMappingClass()
        {
            var config = new MappingConfiguration().Define(new ManyDataTypesPocoMappingCaseSensitive());
            var table = new Table<ManyDataTypesPoco>(_session, config);
            table.Create();

            var mapper = new Mapper(_session, config);
            ManyDataTypesPoco manyTypesInstance = ManyDataTypesPoco.GetRandomInstance();

            mapper.Insert(manyTypesInstance);
            string cqlSelect = string.Format("SELECT * from \"{0}\" where \"{1}\"='{2}'", table.Name, "StringType", manyTypesInstance.StringType);
            ManyDataTypesPoco.KeepTryingSelectAndAssert(mapper, cqlSelect, new List<ManyDataTypesPoco>() { manyTypesInstance });
        }
        private MappingConfiguration<IdentityUser> CraeteIdentityUserMapping()
        {
            MappingConfiguration<IdentityUser> identityUserMapping = new MappingConfiguration<IdentityUser>();
            identityUserMapping.MapType(user => new 
            {
                Id = user.Id,
                Name = user.UserName, 
                PasswordHash = user.PasswordHash
            }).ToTable("IdentityUsers");
            identityUserMapping.HasProperty(x => x.Id).IsIdentity();

            return identityUserMapping;
        }