protected override void OnModelCreating(MongoModelBuilder modelBuilder) { var consumer = modelBuilder.Entity <Consumer>(); consumer.SetIndexes(x => x.Ascending(y => y.Code).IsUnique()); consumer.CreateMap( x => { x.AutoMap(); x.MapCreator(y => new Consumer(y.Id, y.Code, y.Name, y.ClientId)); }); var pnr = modelBuilder.Entity <Pnr>(); pnr.SetIndexes( x => x.Ascending(y => y.PnrId).IsUnique(), x => x.Ascending(y => y.Airline), x => x.Ascending(y => y.Agent), x => x.Ascending(y => y.BookedVia), x => x.Ascending(y => y.Company), x => x.Ascending(y => y.Created), x => x.Ascending(y => y.CustomerType), x => x.Ascending(y => y.IntlAirline), x => x.Ascending(y => y.IsInternational), x => x.Ascending(y => y.IssuedBy), x => x.Ascending(y => y.IssuedVia), x => x.Ascending(y => y.IssuedWithLg), x => x.Ascending(y => y.PassivePnrCode), x => x.Ascending(y => y.PassivePcc), x => x.Ascending(y => y.PassivePnrCode), x => x.Ascending(y => y.PaymentType), x => x.Ascending(y => y.Pcc), x => x.Ascending(y => y.PnrCode), x => x.Ascending(y => y.PnrNumericCode), x => x.Ascending(y => y.PnrReff), x => x.Ascending(y => y.PostStatus), x => x.Ascending(y => y.Prefix), x => x.Ascending(y => y.PrintStatus), x => x.Ascending(y => y.RequestToIssuedWithLG), x => x.Ascending(y => y.Reserved), x => x.Ascending(y => y.RsvNotifSent), x => x.Ascending(y => y.RoomTypeMapping), x => x.Ascending(y => y.Source), x => x.Ascending(y => y.SourcePnrCode), x => x.Ascending(y => y.Status), x => x.Ascending(y => y.StatusPassiveSegment), x => x.Ascending(y => y.Ticketed), x => x.Ascending(y => y.TimeLimit), x => x.Ascending(y => y.TransactionStatus), x => x.Ascending(y => y.UseInsurance), x => x.Ascending(y => y.Username) ); pnr.CreateMap( x => { x.AutoMap(); x.MapIdMember(c => c.Id).SetIdGenerator(CombGuidGenerator.Instance); }); }
protected override void OnModelCreating(MongoModelBuilder modelBuilder) { modelBuilder.Entity <Contact>() .CreateMap( x => { x.AutoMap(); x.MapCreator(y => new Contact(y.Id, y.FirstName, y.LastName, y.Age)); }); modelBuilder.Entity <Contact>() .SetIndexes( x => x.Ascending(y => y.FirstName), x => x.Ascending(y => y.LastName), x => x.Ascending(y => y.Age)); }
private Dictionary <Type, IMongoEntityModel> InitializeCollectionsInternal() { var stopwatch = Logger.StartStopwatch(); Logger.LogInformation($"Start InitializeCollectionsInternal"); var modelBuilder = new MongoModelBuilder(); // Invoke MongoCollectionAttribute var collectionProperties = from property in this.GetType().GetTypeInfo().GetProperties(BindingFlags.Public | BindingFlags.Instance) where ReflectionHelper.IsAssignableToGenericType(property.PropertyType, typeof(IMongoCollection <>)) && typeof(IEntity).IsAssignableFrom(property.PropertyType.GenericTypeArguments[0]) select property; foreach (var collectionProperty in collectionProperties) { var entityType = collectionProperty.PropertyType.GenericTypeArguments[0]; var collectionAttribute = collectionProperty.GetCustomAttributes().OfType <MongoCollectionAttribute>() .FirstOrDefault(); modelBuilder.Entity(entityType, b => { b.CollectionName = collectionAttribute?.CollectionName ?? collectionProperty.Name; }); } // Invoke CreateModel CreateModel(modelBuilder); // Build Model var entityModels = modelBuilder.GetEntities() .ToDictionary(x => x.EntityType, x => x); stopwatch?.Stop(); Logger.LogInformation("End InitializeCollectionsInternal, elapsed time: {elapsedTime}", Logger.GetElapsedTime(stopwatch)); stopwatch = null; return(entityModels); }
protected virtual void CreateModel(MongoModelBuilder modelBuilder) { }