Exemple #1
0
 public void RegTo(ConfigurationRegistrar confRegistrar)
 {
     var r = new EntityTypeConfiguration<UserInfo>();
     r.ToTable("UserInfo");
     r.HasKey(p => p.AutoId);
     confRegistrar.Add<UserInfo>(r);
 }
        /// <summary>
        /// Figures out the key properties and marks them as Keys in the EDM model.
        /// </summary>
        /// <param name="entity">The entity type being configured.</param>
        /// <param name="model">The <see cref="ODataModelBuilder"/>.</param>
        public override void Apply(EntityTypeConfiguration entity, ODataConventionModelBuilder model)
        {
            if (entity == null)
            {
                throw Error.ArgumentNull("entity");
            }

            // Suppress the EntityKeyConvention if there is any key in EntityTypeConfiguration.
            if (entity.Keys.Any() || entity.EnumKeys.Any())
            {
                return;
            }

            // Suppress the EntityKeyConvention if base type has any key.
            if (entity.BaseType != null && entity.BaseType.Keys().Any())
            {
                return;
            }

            PropertyConfiguration key = GetKeyProperty(entity);
            if (key != null)
            {
                entity.HasKey(key.PropertyInfo);
            }
        }
 /// <summary>Defines the mapping information for the entity 'ApiDataSource'</summary>
 /// <param name="config">The configuration to modify.</param>
 protected virtual void MapApiDataSource(EntityTypeConfiguration<ApiDataSource> config)
 {
     config.ToTable("ApiDataSource");
     config.HasKey(t => t.Id);
     config.Property(t => t.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
     config.Property(t => t.SourceName).HasMaxLength(50).IsRequired();
     config.Property(t => t.SourceBaseUrl).HasMaxLength(200);
 }
 /// <summary>Defines the mapping information for the entity 'MovieNotFound'</summary>
 /// <param name="config">The configuration to modify.</param>
 protected virtual void MapMovieNotFound(EntityTypeConfiguration<MovieNotFound> config)
 {
     config.ToTable("MovieNotFound");
     config.HasKey(t => new { t.ItemId, t.ItemSource });
     config.Property(t => t.ItemId).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
     config.Property(t => t.ItemSource).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
     config.Property(t => t.RowId).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity).IsRequired();
     config.Property(t => t.ItemSearchTitle).HasMaxLength(100);
     config.Property(t => t.ItemSearchYear);
     config.Property(t => t.AddedOn);
     config.Property(t => t.ChangedOn);
 }
        public void Configure(DbModelBuilder modelBuilder)
        {
            EntityTypeConfiguration <Ticket> reservationModel = modelBuilder.Entity <Ticket>();

            reservationModel.HasKey(model => model.Id);
            reservationModel.Property(model => model.ProjectionId).IsRequired();
            reservationModel.Property(model => model.Guid).IsRequired();
            reservationModel.Property(model => model.ProjectionStartDate).IsRequired();
            reservationModel.Property(model => model.MovieName).IsRequired();
            reservationModel.Property(model => model.CinemaName).IsRequired();
            reservationModel.Property(model => model.RoomNum).IsRequired();
            reservationModel.Property(model => model.Row).IsRequired();
            reservationModel.Property(model => model.Column).IsRequired();
        }
Exemple #6
0
        /// <summary>
        /// Configures the property as a key on the edm type.
        /// </summary>
        /// <param name="edmProperty">The key property.</param>
        /// <param name="structuralTypeConfiguration">The edm type being configured.</param>
        /// <param name="attribute">The <see cref="Attribute"/> found on the property.</param>
        public override void Apply(PrimitivePropertyConfiguration edmProperty, StructuralTypeConfiguration structuralTypeConfiguration, Attribute attribute)
        {
            if (edmProperty == null)
            {
                throw Error.ArgumentNull("edmProperty");
            }

            EntityTypeConfiguration entity = structuralTypeConfiguration as EntityTypeConfiguration;

            if (entity != null)
            {
                entity.HasKey(edmProperty.PropertyInfo);
            }
        }
Exemple #7
0
        private EntityTypeConfiguration <HandlerRecordData> HandlerInfoConfiguration()
        {
            var config = new EntityTypeConfiguration <HandlerRecordData>();

            config.HasKey(handler => new { handler.MessageId, handler.MessageTypeCode, handler.HandlerTypeCode });
            config.Property(handler => handler.MessageId).IsRequired().HasColumnType("char").HasMaxLength(36);
            config.Property(handler => handler.MessageTypeCode).IsRequired().HasColumnType("int");
            config.Property(handler => handler.HandlerTypeCode).HasColumnType("int");
            config.Property(handler => handler.Timestamp).HasColumnName("OnCreated").HasColumnType("datetime");

            config.ToTable("Cqrs_handlers");

            return(config);
        }
Exemple #8
0
 public ContactMap(EntityTypeConfiguration <Contact> entityTypeConfiguration)
 {
     entityTypeConfiguration.ToTable("Contact");
     entityTypeConfiguration.HasKey(p => p.Id).Property(p => p.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
     entityTypeConfiguration.Property(u => u.FirstName).IsRequired().HasMaxLength(50);
     entityTypeConfiguration.Property(u => u.LastName).IsRequired().HasMaxLength(50);
     entityTypeConfiguration.Property(u => u.Email).IsRequired().HasMaxLength(50);
     entityTypeConfiguration.Property(u => u.PhoneNumber).IsRequired().HasMaxLength(50);
     entityTypeConfiguration.Property(u => u.Status).IsRequired();
     entityTypeConfiguration.HasRequired(t => t.CreatedByUser).WithMany().HasForeignKey(t => t.CreatedByUserId);
     entityTypeConfiguration.Property(u => u.CreatedDate).IsRequired();
     entityTypeConfiguration.HasOptional(t => t.ModifiedByUser).WithMany().HasForeignKey(t => t.ModifiedByUserId);
     entityTypeConfiguration.Property(u => u.ModifiedDate);
 }
        public void Configure(DbModelBuilder modelBuilder)
        {
            EntityTypeConfiguration <Reservation> projectionModel = modelBuilder.Entity <Reservation>();

            projectionModel.HasKey(model => model.Id);
            projectionModel.Property(model => model.ProjectionStartDate).IsRequired();
            projectionModel.Property(model => model.MovieName).IsRequired();
            projectionModel.Property(model => model.CinemaName).IsRequired();
            projectionModel.Property(model => model.RoomNumber).IsRequired();
            projectionModel.Property(model => model.Row).IsRequired();
            projectionModel.Property(model => model.Column).IsRequired();
            projectionModel.Property(model => model.IsCancelled);
            projectionModel.Property(model => model.ProjectionId).IsRequired();
        }
Exemple #10
0
        private void MapActivity(EntityTypeConfiguration <Activity> entity)
        {
            entity.HasKey(k => k.Id).ToTable("Activities");

            entity.Property(k => k.Id).HasColumnName("ActivityID");

            entity.Property(k => k.Name).HasColumnName("Activity");

            entity.Property(k => k.ImagePath).HasColumnName("imagepath");

            entity.Property(k => k.Category).HasColumnName("Category");

            entity.HasMany(k => k.Equipments).WithMany().Map(m => m.MapLeftKey("ActivityID").MapRightKey("EquipmentID").ToTable("ActivityEquipment"));
        }
Exemple #11
0
 /// <summary>
 /// Настройка таблицы ролей
 /// </summary>
 /// <param name="configuration"></param>
 private void ConfigurateRole(EntityTypeConfiguration <Role> configuration)
 {
     configuration.HasKey(role => role.Id);
     configuration.Property(role => role.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
     configuration.Property(role => role.Name).HasMaxLength(50);
     configuration.Property(role => role.Name).HasColumnAnnotation(IndexAnnotation.AnnotationName,
                                                                   new IndexAnnotation(new IndexAttribute()));
     configuration.HasMany(role => role.Users).WithMany(user => user.Roles).Map(cs =>
     {
         cs.MapLeftKey("RoleId");
         cs.MapRightKey("UserId");
         cs.ToTable("UserRole");
     });
 }
        private void ConfigureBookEntity(EntityTypeConfiguration <Book> bookEntity)
        {
            bookEntity.HasKey(b => b.Id);

            bookEntity.Property(b => b.Name).IsRequired();
            bookEntity.Property(b => b.Genre).IsRequired();
            bookEntity.Property(b => b.Language).IsRequired();
            bookEntity.Property(b => b.Price).IsRequired();

            bookEntity
            .HasRequired(b => b.Distributor)
            .WithMany()
            .HasForeignKey(b => b.DistributorId);
        }
        public void HasKeyOnDerivedTypes_Throws_IfCallHasKeyFirst_ThenDerivedFrom()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();

            builder.EntityType <Vehicle>().Abstract();
            builder.EntityType <Motorcycle>().DerivesFrom <Vehicle>().HasKey(m => m.ID);
            EntityTypeConfiguration <SportBike> sportBikeType = builder.EntityType <SportBike>();

            // Act & Assert
            ExceptionAssert.Throws <InvalidOperationException>(() => sportBikeType.HasKey(s => s.SportBikeProperty_NotVisible).DerivesFrom <Motorcycle>(),
                                                               "Cannot define keys on type 'Microsoft.AspNet.OData.Test.Builder.TestModels.SportBike' deriving from 'Microsoft.AspNet.OData.Test.Builder.TestModels.Motorcycle'. " +
                                                               "The base type in the entity inheritance hierarchy already contains keys.");
        }
        private void ConfigureCartEntity(EntityTypeConfiguration <Cart> cartEntity)
        {
            cartEntity.HasKey(c => new { c.BuyerId, c.BookId });

            cartEntity
            .HasRequired(c => c.Buyer)
            .WithMany()
            .HasForeignKey(c => c.BuyerId);

            cartEntity
            .HasRequired(c => c.Book)
            .WithMany()
            .HasForeignKey(c => c.BookId);
        }
        private void ConfigureReviewEntity(EntityTypeConfiguration <Review> reviewEntity)
        {
            reviewEntity.HasKey(r => r.Id);

            reviewEntity
            .HasRequired(r => r.Book)
            .WithMany()
            .HasForeignKey(r => r.BookId);

            reviewEntity
            .HasRequired(r => r.Buyer)
            .WithMany()
            .HasForeignKey(r => r.BuyerId);
        }
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);


            base.OnModelCreating(modelBuilder);
            EntityTypeConfiguration <Category> entityTypeConfiguration = modelBuilder.Entity <Category>();

            entityTypeConfiguration.ToTable("Category");
            entityTypeConfiguration.HasKey(e => e.CategoryID);
            entityTypeConfiguration.Property(t => t.CategoryName);
            //modelBuilder.Types< Category>().Configure(item=>item.Ignore(e=>e.CategoryName));
            //entityTypeConfiguration.Property(e => e.CategoryID).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
        }
Exemple #17
0
        public static IEdmModel GetExplicitModel()
        {
            ODataModelBuilder builder = new ODataModelBuilder();
            EntityTypeConfiguration <Window> windowType = builder.EntityType <Window>();

            windowType.HasKey(a => a.Id);
            windowType.Property(a => a.Name).IsRequired();
            windowType.ComplexProperty(w => w.CurrentShape).IsNullable();
            windowType.CollectionProperty(w => w.OptionalShapes);
            windowType.CollectionProperty(w => w.PolygonalShapes);
            windowType.HasOptional <Window>(w => w.Parent);

            ComplexTypeConfiguration <Shape> shapeType = builder.ComplexType <Shape>();

            shapeType.Property(s => s.HasBorder);
            shapeType.Abstract();

            ComplexTypeConfiguration <Circle> circleType = builder.ComplexType <Circle>();

            circleType.ComplexProperty(c => c.Center);
            circleType.Property(c => c.Radius);
            circleType.DerivesFrom <Shape>();

            ComplexTypeConfiguration <Polygon> polygonType = builder.ComplexType <Polygon>();

            polygonType.CollectionProperty(p => p.Vertexes);
            polygonType.DerivesFrom <Shape>();

            ComplexTypeConfiguration <Rectangle> rectangleType = builder.ComplexType <Rectangle>();

            rectangleType.ComplexProperty(r => r.TopLeft);
            rectangleType.Property(r => r.Width);
            rectangleType.Property(r => r.Height);
            rectangleType.DerivesFrom <Polygon>();

            ComplexTypeConfiguration <Point> pointType = builder.ComplexType <Point>();

            pointType.Property(p => p.X);
            pointType.Property(p => p.Y);

            EntitySetConfiguration <Window> windows = builder.EntitySet <Window>("Windows");

            //       windows.HasEditLink(link, true);
            //    windows.HasIdLink(link, true);
            windows.HasOptionalBinding(c => c.Parent, "Windows");

            builder.Namespace = typeof(Window).Namespace;

            return(builder.GetEdmModel());
        }
Exemple #18
0
        private EntityTypeConfiguration<HandlerRecord> HandlerInfoConfiguration()
        {
            var config = new EntityTypeConfiguration<HandlerRecord>();

            config.HasKey(handler => new { handler.MessageId, handler.MessageTypeCode, handler.HandlerTypeCode });
            config.Property(handler => handler.MessageId).IsRequired().HasColumnType("char").HasMaxLength(36);
            config.Property(handler => handler.MessageTypeCode).IsRequired().HasColumnType("int");
            config.Property(handler => handler.HandlerTypeCode).HasColumnType("int");
            config.Property(handler => handler.Timestamp).HasColumnName("OnCreated").HasColumnType("datetime");

            config.ToTable("thinknet_handlers");

            return config;
        }
Exemple #19
0
        public static void Map(DbModelBuilder modelBuilder)
        {
            EntityTypeConfiguration <LogSystemLogin> loginSystemConfig = modelBuilder.Entity <LogSystemLogin>();

            loginSystemConfig.HasKey(x => new { x.UserID, x.DateOfSystemLogin });

            loginSystemConfig.Property(x => x.DateOfSystemLogin).IsRequired().HasColumnType("date");
            loginSystemConfig.Property(x => x.DateOfSystemLogout).IsOptional().HasColumnType("date");


            loginSystemConfig.HasRequired(h => h.User).WithMany(h => h.LogSystemLogins)
            .HasForeignKey(h => h.UserID)
            .WillCascadeOnDelete(false);
        }
        public void ComplexTypeConvention_RemovesAnyKeyFromEntityConfiguration()
        {
            // Arrange
            EntityTypeConfiguration entity = CreateEntitytypeConfigurationMock();

            entity.HasKey(new MockPropertyInfo(typeof(int), "Id"));
            ComplexTypeAttributeConvention convention = new ComplexTypeAttributeConvention();

            // Act
            convention.Apply(entity, null, null);

            // Assert
            Assert.Empty(entity.Keys);
        }
Exemple #21
0
        public static void Map(EntityTypeConfiguration <Account> config)
        {
            config.HasKey(m => m.Id);

            config.Property(m => m.Name).HasColumnType("varchar").HasColumnName("Name").IsRequired();

            config.Property(m => m.Login).IsRequired();

            config.Property(m => m.Password).IsRequired();

            config.Property(m => m.Email).IsRequired();

            config.HasMany(m => m.Objectives);
        }
Exemple #22
0
        public void GetIfMatchOrNoneMatch_ReturnsETag_SetETagHeaderValue(string header)
        {
            // Arrange
            HttpRequestMessage request      = new HttpRequestMessage();
            HttpConfiguration  cofiguration = new HttpConfiguration();

            request.SetConfiguration(cofiguration);
            Dictionary <string, object> properties = new Dictionary <string, object> {
                { "Name", "Foo" }
            };
            EntityTagHeaderValue etagHeaderValue = new DefaultODataETagHandler().CreateETag(properties);

            if (header.Equals("IfMatch"))
            {
                request.Headers.IfMatch.Add(etagHeaderValue);
            }
            else
            {
                request.Headers.IfNoneMatch.Add(etagHeaderValue);
            }

            ODataModelBuilder builder = new ODataModelBuilder();
            EntityTypeConfiguration <Customer> customer = builder.Entity <Customer>();

            customer.HasKey(c => c.Id);
            customer.Property(c => c.Id);
            customer.Property(c => c.Name).IsConcurrencyToken();
            IEdmModel model = builder.GetEdmModel();

            Mock <ODataPathSegment> mockSegment = new Mock <ODataPathSegment> {
                CallBase = true
            };

            mockSegment.Setup(s => s.GetEdmType(null)).Returns(model.GetEdmType(typeof(Customer)));
            mockSegment.Setup(s => s.GetEntitySet(null)).Returns((IEdmEntitySet)null);
            ODataPath odataPath = new ODataPath(new[] { mockSegment.Object });

            request.ODataProperties().Path = odataPath;
            ODataQueryContext context      = new ODataQueryContext(model, typeof(Customer));

            // Act
            ODataQueryOptions <Customer> query = new ODataQueryOptions <Customer>(context, request);
            ETag    result        = header.Equals("IfMatch") ? query.IfMatch : query.IfNoneMatch;
            dynamic dynamicResult = result;

            // Assert
            Assert.Equal("Foo", result["Name"]);
            Assert.Equal("Foo", dynamicResult.Name);
        }
        public void DynamicDictionaryProperty_Works_ToSetEntityTypeAsOpen()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();

            // Act
            EntityTypeConfiguration <SimpleOpenEntityType> entityType = builder.EntityType <SimpleOpenEntityType>();

            entityType.HasKey(c => c.Id);
            entityType.Property(c => c.Name);
            entityType.HasDynamicProperties(c => c.DynamicProperties);

            // Act & Assert
            Assert.True(entityType.IsOpen);
        }
Exemple #24
0
        private EntityTypeConfiguration<Snapshot> SnapshotConfiguration()
        {
            var config = new EntityTypeConfiguration<Snapshot>();

            config.HasKey(snapshot => new { snapshot.AggregateRootId, snapshot.AggregateRootTypeCode });
            config.Property(snapshot => snapshot.AggregateRootId).IsRequired().HasColumnType("char").HasMaxLength(36);
            config.Property(snapshot => snapshot.AggregateRootTypeCode).IsRequired().HasColumnType("int");
            config.Property(snapshot => snapshot.Version).HasColumnType("int");
            config.Property(snapshot => snapshot.Data).HasColumnType("varchar");
            config.Property(snapshot => snapshot.Timestamp).HasColumnName("OnCreated").HasColumnType("datetime");

            config.ToTable("thinknet_snapshots");

            return config;
        }
Exemple #25
0
        public override void Build(EntityTypeConfiguration <Permission> configuration)
        {
            configuration.HasKey(x => x.ID);
            configuration.Property(x => x.ID).HasColumnName("PermissionID");
            configuration.HasRequired(x => x.Application).WithMany(x => x.Permissions).Map(m => m.MapKey("ApplicationID"));

            configuration.HasMany(x => x.Roles)
            .WithMany(x => x.Permissions)
            .Map(map =>
            {
                map.ToTable("PermissionsInRoles");
                map.MapLeftKey("PermissionID");
                map.MapRightKey("RoleID");
            });
        }
        public static void Map(DbModelBuilder modelBuilder)
        {
            EntityTypeConfiguration <Subject> subjectConfig = modelBuilder.Entity <Subject>();

            subjectConfig.HasKey(x => x.Id);

            subjectConfig.Property(x => x.Name).IsRequired().HasMaxLength(100).HasColumnType("varchar");

            subjectConfig.Property(x => x.DateOfCreation).IsOptional().HasColumnType("date");


            subjectConfig.HasRequired(t => t.EducationGroup).WithMany(t => t.Subjects)
            .HasForeignKey(t => t.EducationGroupID)
            .WillCascadeOnDelete(false);
        }
        public void ComplexTypeConvention_DoesntApplyToExplicitlyDefinedTypes()
        {
            // Arrange
            EntityTypeConfiguration entity = CreateEntitytypeConfigurationMock();

            entity.AddedExplicitly = true;
            entity.HasKey(new MockPropertyInfo(typeof(int), "Id"));
            ComplexTypeAttributeConvention convention = new ComplexTypeAttributeConvention();

            // Act
            convention.Apply(entity, null, null);

            // Assert
            Assert.Equal(1, entity.Keys.Count());
        }
Exemple #28
0
        private EntityTypeConfiguration <SnapshotData> SnapshotConfiguration()
        {
            var config = new EntityTypeConfiguration <SnapshotData>();

            config.HasKey(snapshot => new { snapshot.AggregateRootId, snapshot.AggregateRootTypeCode });
            config.Property(snapshot => snapshot.AggregateRootId).IsRequired().HasColumnType("char").HasMaxLength(36);
            config.Property(snapshot => snapshot.AggregateRootTypeCode).IsRequired().HasColumnType("int");
            config.Property(snapshot => snapshot.Version).HasColumnType("int");
            config.Property(snapshot => snapshot.Data).HasColumnType("varchar");
            config.Property(snapshot => snapshot.Timestamp).HasColumnName("OnCreated").HasColumnType("datetime");

            config.ToTable("Cqrs_snapshots");

            return(config);
        }
        private static IEdmModel CreateModelForFullMetadata(bool sameLinksForIdAndEdit, bool sameLinksForEditAndRead)
        {
            ODataModelBuilder builder = new ODataModelBuilder();

            EntitySetConfiguration <MainEntity> mainSet = builder.EntitySet <MainEntity>("MainEntity");

            Func <EntityInstanceContext <MainEntity>, string> idLinkFactory = (e) =>
                                                                              CreateAbsoluteLink("/MainEntity/id/" + e.EntityInstance.Id.ToString());

            mainSet.HasIdLink(idLinkFactory, followsConventions: true);

            Func <EntityInstanceContext <MainEntity>, string> editLinkFactory;

            if (!sameLinksForIdAndEdit)
            {
                editLinkFactory = (e) => CreateAbsoluteLink("/MainEntity/edit/" + e.EntityInstance.Id.ToString());
                mainSet.HasEditLink(editLinkFactory, followsConventions: false);
            }

            Func <EntityInstanceContext <MainEntity>, string> readLinkFactory;

            if (!sameLinksForEditAndRead)
            {
                readLinkFactory = (e) => CreateAbsoluteLink("/MainEntity/read/" + e.EntityInstance.Id.ToString());
                mainSet.HasReadLink(readLinkFactory, followsConventions: false);
            }

            EntityTypeConfiguration <MainEntity> main = mainSet.EntityType;

            main.HasKey <int>((e) => e.Id);
            main.Property <short>((e) => e.Int16);
            NavigationPropertyConfiguration mainToRelated = mainSet.EntityType.HasRequired((e) => e.Related);

            main.Action("DoAlways").ReturnsCollectionFromEntitySet <MainEntity>("MainEntity").HasActionLink((c) =>
                                                                                                            CreateAbsoluteUri("/MainEntity/DoAlways/" + ((MainEntity)(c.EntityInstance)).Id),
                                                                                                            followsConventions: true);
            main.TransientAction("DoSometimes").ReturnsCollectionFromEntitySet <MainEntity>(
                "MainEntity").HasActionLink((c) =>
                                            CreateAbsoluteUri("/MainEntity/DoSometimes/" + ((MainEntity)(c.EntityInstance)).Id),
                                            followsConventions: false);

            mainSet.HasNavigationPropertyLink(mainToRelated, (c, p) => new Uri("/MainEntity/RelatedEntity/" +
                                                                               c.EntityInstance.Id, UriKind.Relative), followsConventions: true);

            EntitySetConfiguration <RelatedEntity> related = builder.EntitySet <RelatedEntity>("RelatedEntity");

            return(builder.GetEdmModel());
        }
Exemple #30
0
        private EntityTypeConfiguration<Event> EventDataConfiguration()
        {
            var config = new EntityTypeConfiguration<Event>();

            config.HasKey(@event => new { @event.AggregateRootId, @event.AggregateRootTypeCode, @event.Version });
            config.Property(@event => @event.AggregateRootId).IsRequired().HasColumnType("char").HasMaxLength(36);
            config.Property(@event => @event.AggregateRootTypeCode).IsRequired().HasColumnType("int");
            config.Property(@event => @event.Version).HasColumnType("int");
            config.Property(@event => @event.CorrelationId).HasColumnType("char").HasMaxLength(36);
            config.Property(@event => @event.Payload).HasColumnType("varchar");
            config.Property(@event => @event.Timestamp).HasColumnName("OnCreated").HasColumnType("datetime");

            config.ToTable("thinknet_events");

            return config;
        }
Exemple #31
0
        private void MapUsers(EntityTypeConfiguration <User> entity)
        {
            entity.HasKey(p => p.Id).ToTable("Users", "intranet");

            entity.Property(p => p.Id).HasColumnName("ID");

            entity.Property(p => p.Name);

            entity.Property(p => p.Email);

            entity.Property(p => p.SiteId).HasColumnName("FKSiteID");

            entity.HasRequired(p => p.Site).WithMany().HasForeignKey(p => p.SiteId);

            entity.HasMany(e => e.Roles).WithMany().Map(m => m.MapLeftKey("FKUserID").MapRightKey("FKRoleID").ToTable("UserRoles", "intranet"));
        }
        public override void Configure(EntityTypeConfiguration <StockEvent> builder)
        {
            builder.ToTable("StockEvent", "dbo");

            builder.HasKey(x => x.Id);
            builder.Property(x => x.Id)
            .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            builder.HasRequired(x => x.Warehouse)
            .WithMany()
            .HasForeignKey(x => x.WarehouseId);

            builder.HasRequired(x => x.Product)
            .WithMany()
            .HasForeignKey(x => x.ProductId);
        }
Exemple #33
0
        private EntityTypeConfiguration <EventData> EventDataConfiguration()
        {
            var config = new EntityTypeConfiguration <EventData>();

            config.HasKey(@event => new { @event.AggregateRootId, @event.AggregateRootTypeCode, @event.Version });
            config.Property(@event => @event.AggregateRootId).IsRequired().HasColumnType("char").HasMaxLength(36);
            config.Property(@event => @event.AggregateRootTypeCode).IsRequired().HasColumnType("int");
            config.Property(@event => @event.Version).HasColumnType("int");
            config.Property(@event => @event.CorrelationId).HasColumnType("char").HasMaxLength(36);
            config.Property(@event => @event.Payload).HasColumnType("varchar");
            config.Property(@event => @event.Timestamp).HasColumnName("OnCreated").HasColumnType("datetime");

            config.ToTable("Cqrs_events");

            return(config);
        }
Exemple #34
0
        public void Configure(DbModelBuilder modelBuilder)
        {
            if (!TypeCache <TSaga> .ReadWritePropertyCache.TryGetProperty("CorrelationId", out ReadWriteProperty <TSaga> _))
            {
                throw new ConfigurationException("The CorrelationId property must be read/write for use with Entity Framework. Add a setter to the property.");
            }

            EntityTypeConfiguration <TSaga> cfg = modelBuilder.Entity <TSaga>();

            cfg.HasKey(t => t.CorrelationId);

            cfg.Property(t => t.CorrelationId)
            .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            Configure(cfg, modelBuilder);
        }
        public static void Map(DbModelBuilder modelBuilder)
        {
            EntityTypeConfiguration <Employee> entity = modelBuilder.Entity <Employee>();

            entity.HasKey(e => e.Id);
            entity.Property(e => e.FirstName).IsRequired().HasMaxLength(50).HasColumnType("varchar");
            entity.Property(e => e.LastName).IsRequired().HasMaxLength(50).HasColumnType("varchar");
            entity.Property(e => e.DateOfBirth).HasColumnType("date").IsOptional();
            entity.Property(e => e.EmailAddress).HasMaxLength(100);
            entity.Property(e => e.Salary).HasColumnType("money");
            entity.Property(e => e.PhoneNumber).HasMaxLength(20);
            entity.Property(e => e.HireDate).HasColumnType("date");

            entity.HasRequired(e => e.Department).WithMany(e => e.Employees)
            .HasForeignKey(e => e.DepartmentId).WillCascadeOnDelete(false);
        }
Exemple #36
0
        private void MapLodging(EntityTypeConfiguration <Lodging> entity)
        {
            entity.HasKey(k => k.Id).ToTable("Lodging");

            entity.Property(k => k.Id).HasColumnName("LodgingID");

            entity.Property(k => k.Name).HasColumnName("LodgingName");

            entity.Property(k => k.ContactId).HasColumnName("ContactID");

            entity.Property(k => k.LocationId).HasColumnName("LocationID");

            entity.HasRequired(k => k.Contact).WithMany().HasForeignKey(k => k.ContactId);

            entity.Map <Resort>(m => m.Requires("Resort").HasValue("1"));
        }
Exemple #37
0
        protected void buildCustomers(EntityTypeConfiguration<Customer> customerEntity)
        {
            customerEntity
                .HasKey(x => x.customerID)
                .Property(x => x.name).IsRequired()
                .HasMaxLength(50);

            customerEntity
                .HasMany(x => x.orders)
                .WithRequired(x => x.customer)
                .HasForeignKey(x => x.customerID)
                .WillCascadeOnDelete();

            customerEntity
                .Property(x => x.timeStamp)
                .IsRequired();
        }
Exemple #38
0
        public void Configure_HasColumnName_using_configuration()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            var configuration = new EntityTypeConfiguration <UnitMeasure>();

            configuration.HasKey(u => u.UnitMeasureCode);
            configuration.Property(u => u.UnitMeasureCode).HasColumnName("Code");

            modelBuilder.Configurations.Add(configuration);

            var databaseMapping = BuildMapping(modelBuilder);

            databaseMapping.AssertValid();

            databaseMapping.Assert <UnitMeasure>("UnitMeasures").HasColumns("Code", "Name");
        }
        /// <summary>
        /// Figures out the key properties and marks them as Keys in the EDM model.
        /// </summary>
        /// <param name="entity">The entity type being configured.</param>
        /// <param name="model">The <see cref="ODataModelBuilder"/>.</param>
        public override void Apply(EntityTypeConfiguration entity, ODataModelBuilder model)
        {
            if (entity == null)
            {
                throw Error.ArgumentNull("entity");
            }

            // Try to figure out keys only if there is no base type.
            if (entity.BaseType == null)
            {
                PropertyConfiguration key = GetKeyProperty(entity);
                if (key != null)
                {
                    entity.HasKey(key.PropertyInfo);
                }
            }
        }
        /// <summary>
        /// Configure LongShortUrl entityTypeConfiguration
        /// </summary>
        /// <param name="modelBuilder"></param>
        private static void configureEntity(EntityTypeConfiguration<LongShortUrl> entityTypeConfiguration)
        {
            entityTypeConfiguration.HasKey(e => e.Id);

            entityTypeConfiguration.Property(e => e.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            entityTypeConfiguration.Property(e => e.ShortUrlId).IsRequired().HasMaxLength(10);

            entityTypeConfiguration.Property(e => e.LongUrl).IsRequired().HasMaxLength(2000);

            entityTypeConfiguration.Property(e => e.CreatedDate).IsRequired();

            entityTypeConfiguration
                .HasMany(e => e.LongShortUrlUsers)
                .WithOptional()
                .HasForeignKey(e => e.LongShortUrlId)
                .WillCascadeOnDelete();

        }
 /// <summary>Defines the mapping information for the entity 'MovieCreditResult'</summary>
 /// <param name="config">The configuration to modify.</param>
 protected virtual void MapMovieCreditResult(EntityTypeConfiguration<MovieCreditResult> config)
 {
     config.ToTable("MovieCreditResult");
     config.HasKey(t => new { t.ItemId, t.RowId });
     config.Property(t => t.ItemId).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
     config.Property(t => t.RowId).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
     config.Property(t => t.ItemSearchTitle).HasMaxLength(100);
     config.Property(t => t.ApiUrl).HasMaxLength(200);
     config.Property(t => t.ResultNum);
     config.Property(t => t.Name).HasMaxLength(100);
     config.Property(t => t.Order);
     config.Property(t => t.CastId).HasColumnName("Cast_Id");
     config.Property(t => t.Character).HasMaxLength(100);
     config.Property(t => t.CreditId).HasColumnName("Credit_Id").HasMaxLength(50);
     config.Property(t => t.TmdId);
     config.Property(t => t.ProfilePath).HasColumnName("Profile_Path").HasMaxLength(200);
     config.Property(t => t.AddedOn);
     config.Property(t => t.ChangedOn);
 }
Exemple #42
0
        protected void buildBlobs(EntityTypeConfiguration<Blob> blobEntity)
        {
            blobEntity
                .HasKey(x => x.blobID);

            blobEntity
                .Property(x => x.data)
                .IsRequired();

            blobEntity
                .Property(x => x.name)
                .IsRequired()
                .HasMaxLength(500);

            blobEntity
                .Property(x => x.timeStamp)
                .IsRequired();

            blobEntity
                .Property(x => x.type)
                .IsRequired();
        }
 /// <summary>
 /// Maps the type <see cref="Reference.Domain.Entities.Vare"/> to the table defined by <seealso cref="TableAttribute.Name"/>.
 /// </summary>
 protected virtual void MapVare(EntityTypeConfiguration<Vare> config)
 {
     config.ToTable("Vare");
     config.Property(v=>v.Version).IsConcurrencyToken().IsRowVersion();
     config.HasKey(e=>e.Id);
 }
        /// <summary>
        /// Configure LongShortUrlUser entityTypeConfiguration
        /// </summary>
        /// <param name="modelBuilder"></param>
        private static void configureEntity(EntityTypeConfiguration<LongShortUrlUser> entityTypeConfiguration)
        {
            entityTypeConfiguration.HasKey(e => e.Id);

            entityTypeConfiguration.Property(e => e.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            entityTypeConfiguration.Property(e => e.LongShortUrlId).IsRequired();

            entityTypeConfiguration.Property(e => e.IpAddress).IsRequired().HasMaxLength(45);

            entityTypeConfiguration.Property(e => e.UserAgent).IsRequired();

            entityTypeConfiguration.Property(e => e.CreatedDate).IsRequired();

        }
 /// <summary>Defines the mapping information for the entity 'MovieResult'</summary>
 /// <param name="config">The configuration to modify.</param>
 protected virtual void MapMovieResult(EntityTypeConfiguration<MovieResult> config)
 {
     config.ToTable("MovieResult");
     config.HasKey(t => new { t.ItemId, t.ItemSource, t.RowId });
     config.Property(t => t.ItemId).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
     config.Property(t => t.ItemSearchTitle).HasMaxLength(100).IsRequired();
     config.Property(t => t.ItemSource).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
     config.Property(t => t.RowId).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
     config.Property(t => t.ItemSearchYear);
     config.Property(t => t.ApiUrl).HasMaxLength(200);
     config.Property(t => t.ResultTitle).HasMaxLength(100);
     config.Property(t => t.ResultYear);
     config.Property(t => t.IsMovie);
     config.Property(t => t.ResultCt);
     config.Property(t => t.Page);
     config.Property(t => t.TotalPages).HasColumnName("Total_Pages");
     config.Property(t => t.TotalResults).HasColumnName("Total_Results");
     config.Property(t => t.ResultNum);
     config.Property(t => t.GenreIds).HasColumnName("Genre_Ids").HasMaxLength(100);
     config.Property(t => t.OriginalLanguage).HasColumnName("Original_Language").HasMaxLength(50);
     config.Property(t => t.OriginalTitle).HasColumnName("Original_Title").HasMaxLength(100);
     config.Property(t => t.Overview);
     config.Property(t => t.ReleaseDate).HasColumnName("Release_Date").HasMaxLength(50);
     config.Property(t => t.PosterPath).HasColumnName("Poster_Path").HasMaxLength(250);
     config.Property(t => t.Popularity);
     config.Property(t => t.Video);
     config.Property(t => t.VoteAverage).HasColumnName("Vote_Average");
     config.Property(t => t.VoteCount).HasColumnName("Vote_Count");
     config.Property(t => t.Rated).HasMaxLength(50);
     config.Property(t => t.Released).HasMaxLength(50);
     config.Property(t => t.Runtime).HasMaxLength(50);
     config.Property(t => t.Genre).HasMaxLength(50);
     config.Property(t => t.Director).HasMaxLength(100);
     config.Property(t => t.Writer).HasMaxLength(100);
     config.Property(t => t.Actors);
     config.Property(t => t.Plot);
     config.Property(t => t.Language).HasMaxLength(50);
     config.Property(t => t.Country).HasMaxLength(50);
     config.Property(t => t.Awards).HasMaxLength(100);
     config.Property(t => t.Poster).HasMaxLength(200);
     config.Property(t => t.MetaScore).HasMaxLength(50);
     config.Property(t => t.ImdbRating).HasMaxLength(50);
     config.Property(t => t.ImdbVotes).HasMaxLength(50);
     config.Property(t => t.ImdbId).HasMaxLength(50);
     config.Property(t => t.Type).HasMaxLength(100);
     config.Property(t => t.Tmeter).HasColumnName("TMeter").HasMaxLength(100);
     config.Property(t => t.Timage).HasColumnName("TImage").HasMaxLength(200);
     config.Property(t => t.Trating).HasColumnName("TRating").HasMaxLength(50);
     config.Property(t => t.Treviews).HasColumnName("TReviews");
     config.Property(t => t.Tfresh).HasColumnName("TFresh").HasMaxLength(50);
     config.Property(t => t.Trotten).HasColumnName("TRotten").HasMaxLength(50);
     config.Property(t => t.Tconsensus).HasColumnName("TConsensus").HasMaxLength(50);
     config.Property(t => t.TuserMeter).HasColumnName("TUserMeter").HasMaxLength(50);
     config.Property(t => t.TuserRating).HasColumnName("TUserRating").HasMaxLength(50);
     config.Property(t => t.TuserReviews).HasColumnName("TUserReviews");
     config.Property(t => t.Dvd).HasColumnName("DVD").HasMaxLength(100);
     config.Property(t => t.BoxOffice).HasMaxLength(50);
     config.Property(t => t.Production).HasMaxLength(50);
     config.Property(t => t.Website).HasMaxLength(200);
     config.Property(t => t.Response).HasMaxLength(10);
     config.Property(t => t.AddedOn);
     config.Property(t => t.ChangedOn);
 }
Exemple #46
0
        protected void buildOrders(EntityTypeConfiguration<Order> orderEntity)
        {
            orderEntity
                .HasKey(x => x.orderID)
                .Property(x => x.orderDate)
                .IsRequired();

            orderEntity
                .Property(x => x.status)
                .IsRequired();

            orderEntity
                .Property(x => x.address)
                .IsRequired()
                .HasMaxLength(400);

            orderEntity
                .Property(x => x.timeStamp)
                .IsRequired();

            orderEntity
                .HasRequired(x => x.customer)
                .WithMany(x => x.orders);
            orderEntity
                .HasMany(x => x.products)
                .WithRequired(x => x.order)
                .WillCascadeOnDelete();
        }
        public void Configure_HasColumnName_using_configuration_can_be_overriden_using_api()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            var configuration = new EntityTypeConfiguration<UnitMeasure>();

            configuration.HasKey(u => u.UnitMeasureCode);
            configuration.Property(u => u.UnitMeasureCode).HasColumnName("Code");

            modelBuilder.Configurations.Add(configuration);

            modelBuilder.Entity<UnitMeasure>().Property(u => u.UnitMeasureCode).HasColumnName("UnitCode");

            var databaseMapping = BuildMapping(modelBuilder);
            databaseMapping.AssertValid();

            databaseMapping.Assert<UnitMeasure>("UnitMeasures").HasColumns("UnitCode", "Name");
        }
Exemple #48
0
        protected void buildProductDocs(EntityTypeConfiguration<ProductDoc> productDocEntity)
        {
            productDocEntity
                .HasKey(x => new { x.blobID, x.productID });

            productDocEntity
                .HasRequired(x => x.product)
                .WithMany(x => x.files)
                .HasForeignKey(x => x.productID);

            productDocEntity
                .HasRequired(x => x.blob);
        }
Exemple #49
0
        protected void buildProducts(EntityTypeConfiguration<Product> productEntity)
        {
            productEntity
                .HasKey(x => x.productID)
                .Property(x => x.name)
                .HasMaxLength(50);

            productEntity
                .Property(x => x.price)
                .IsRequired();

            productEntity
                .Property(x => x.timeStamp)
                .IsRequired();

            productEntity
                .HasMany(x => x.files)
                .WithRequired(x => x.product)
                .HasForeignKey(x => x.productID)
                .WillCascadeOnDelete();
        }
Exemple #50
0
        protected void buildOrderItems(EntityTypeConfiguration<OrderItem> orderItemEntity)
        {
            orderItemEntity
                .HasKey(x => new { x.productID, x.orderID });

            orderItemEntity
                .HasRequired(x => x.order)
                .WithMany(x => x.products)
                .HasForeignKey(x => x.orderID);

            orderItemEntity
                .Property(x => x.quantity)
                .IsRequired();
        }