/// <summary> /// Generates required data for a OneToMany relationship without embedded documents /// </summary> /// <returns></returns> public static RequiredDataContainer OneToManyNotEmbedded() { // Create ER Stuff Entity Person = new Entity("Person"); Person.AddAttribute("personId"); Person.AddAttribute("name"); Entity Car = new Entity("Car"); Car.AddAttribute("carId"); Car.AddAttribute("name"); Car.AddAttribute("year"); Car.AddAttribute("personId"); Relationship Drives = new Relationship("Drives"); Drives.AddRelationshipEnd(new RelationshipEnd(Person)); Drives.AddRelationshipEnd(new RelationshipEnd(Car)); ERModel Model = new ERModel("PersonCarModel", new List <BaseERElement> { Person, Car, Drives }); // Create MongoDB schema MongoDBCollection PersonCollection = new MongoDBCollection("Person"); PersonCollection.DocumentSchema.AddAttribute("_id"); PersonCollection.DocumentSchema.AddAttribute("name"); MongoDBCollection CarCollection = new MongoDBCollection("Car"); CarCollection.DocumentSchema.AddAttribute("_id"); CarCollection.DocumentSchema.AddAttribute("name"); CarCollection.DocumentSchema.AddAttribute("year"); CarCollection.DocumentSchema.AddAttribute("personId"); MongoSchema Schema = new MongoSchema("PersonCarSchema", new List <MongoDBCollection> { PersonCollection, CarCollection }); // Create Map MapRule PersonRule = new MapRule(Model.FindByName("Person"), Schema.FindByName("Person")); PersonRule.AddRule("personId", "_id"); PersonRule.AddRule("name", "name"); MapRule CarRule = new MapRule(Model.FindByName("Car"), Schema.FindByName("Car")); CarRule.AddRule("carId", "_id"); CarRule.AddRule("name", "name"); CarRule.AddRule("year", "year"); CarRule.AddRule("personId", "personId"); ModelMapping Map = new ModelMapping("PersonCarMap", new List <MapRule> { PersonRule, CarRule }); return(new RequiredDataContainer(Model, Schema, Map)); }
/// <summary> /// Creates a MongoDBSchema and Mapping the is a 1-1 map with the ER model /// </summary> /// <returns></returns> public static RequiredDataContainer MapEntitiesToCollections() { // Create Schema MongoDBCollection UserCol = new MongoDBCollection("User"); UserCol.AddAttributes("_id", "user_name", "user_email", "user_access", "user_newsletter"); MongoDBCollection ProductCol = new MongoDBCollection("Product"); ProductCol.AddAttributes("_id", "product_title", "product_description", "product_short_description", "product_url", "product_category_id", "product_store_id", "product_user_id", "product_published", "product_image"); MongoDBCollection CategoryCol = new MongoDBCollection("Category"); CategoryCol.AddAttributes("_id", "category_name"); MongoDBCollection StoreCol = new MongoDBCollection("Store"); StoreCol.AddAttributes("_id", "store_name", "store_logo"); MongoSchema Schema = new MongoSchema("CMSSchema", new List <MongoDBCollection>() { UserCol, ProductCol, StoreCol, CategoryCol }); // Retrieve ER Model ERModel Model = CreateERModel(); // Build Mapping Entity User = (Entity)Model.FindByName("User"); MapRule UserRules = new MapRule(User, UserCol); UserRules.AddRule("user_id", "_id"); UserRules.AddRule("user_name", "user_name"); UserRules.AddRule("user_email", "user_email"); UserRules.AddRule("user_access", "user_access"); UserRules.AddRule("user_newsletter", "user_newsletter"); Entity Product = (Entity)Model.FindByName("Product"); MapRule ProductRules = new MapRule(Product, ProductCol); ProductRules.AddRule("product_id", "_id"); ProductRules.AddRule("product_title", "product_title"); ProductRules.AddRule("product_description", "product_description"); ProductRules.AddRule("product_short_description", "product_short_description"); ProductRules.AddRule("product_url", "product_url"); ProductRules.AddRule("product_category_id", "product_category_id"); ProductRules.AddRule("product_store_id", "product_store_id"); ProductRules.AddRule("product_user_id", "product_user_id"); ProductRules.AddRule("product_published", "product_published"); ProductRules.AddRule("product_image", "product_image"); Entity Category = (Entity)Model.FindByName("Category"); MapRule CategoryRules = new MapRule(Category, CategoryCol); CategoryRules.AddRule("category_id", "_id"); CategoryRules.AddRule("category_name", "category_name"); Entity Store = (Entity)Model.FindByName("Store"); MapRule StoreRules = new MapRule(Store, StoreCol); StoreRules.AddRule("store_id", "_id"); StoreRules.AddRule("store_name", "store_name"); StoreRules.AddRule("store_logo", "store_logo"); ModelMapping Map = new ModelMapping("CMSMap11", new List <MapRule>() { UserRules, ProductRules, CategoryRules, StoreRules }); return(new RequiredDataContainer(Model, Schema, Map)); }
/// <summary> /// Generates required data to test a One to One relationship /// joining multiple entities with relationship attribute and multiple root attributes /// </summary> /// <returns></returns> public static RequiredDataContainer OneToOneRelationshipMultipleRootAttributes() { // Create ER Stuff Entity Person = new Entity("Person"); Person.AddAttribute("personId", true); Person.AddAttribute("name"); Person.AddAttribute("insuranceId"); Entity Car = new Entity("Car"); Car.AddAttribute("name"); Car.AddAttribute("year"); Car.AddAttribute("engine"); Car.AddAttribute("fuel"); Entity Insurance = new Entity("Insurance"); Insurance.AddAttribute("insuranceId", true); Insurance.AddAttribute("name"); Relationship HasInsurance = new Relationship("HasInsurance"); HasInsurance.AddAttribute("insuranceValue"); HasInsurance.AddRelationshipEnd(new RelationshipEnd(Person)); HasInsurance.AddRelationshipEnd(new RelationshipEnd(Car)); HasInsurance.AddRelationshipEnd(new RelationshipEnd(Insurance)); ERModel Model = new ERModel("PersonCarModel", new List <BaseERElement> { Person, Car, HasInsurance, Insurance }); // Create MongoDB schema MongoDBCollection PersonCollection = new MongoDBCollection("Person"); PersonCollection.DocumentSchema.AddAttribute("_id"); PersonCollection.DocumentSchema.AddAttribute("name"); PersonCollection.DocumentSchema.AddAttribute("car.name"); PersonCollection.DocumentSchema.AddAttribute("car.year"); PersonCollection.DocumentSchema.AddAttribute("carDetails.engine"); PersonCollection.DocumentSchema.AddAttribute("CarDetails.fuel"); PersonCollection.DocumentSchema.AddAttribute("insuranceId"); PersonCollection.DocumentSchema.AddAttribute("insuranceValue"); MongoDBCollection InsuranceCollection = new MongoDBCollection("Insurance"); InsuranceCollection.DocumentSchema.AddAttribute("_id"); InsuranceCollection.DocumentSchema.AddAttribute("name"); MongoSchema Schema = new MongoSchema("PersonCarSchema", new List <MongoDBCollection> { PersonCollection, InsuranceCollection }); // Create Map MapRule PersonRule = new MapRule(Model.FindByName("Person"), Schema.FindByName("Person")); PersonRule.AddRule("personId", "_id"); PersonRule.AddRule("name", "name"); PersonRule.AddRule("carId", "carId"); PersonRule.AddRule("insuranceId", "insuranceId"); MapRule CarRule = new MapRule(Model.FindByName("Car"), Schema.FindByName("Person"), false); CarRule.AddRule("name", "car.name"); CarRule.AddRule("year", "car.year"); CarRule.AddRule("engine", "carDetails.engine"); CarRule.AddRule("fuel", "carDetails.fuel"); MapRule InsuranceRule = new MapRule(Model.FindByName("Insurance"), Schema.FindByName("Insurance")); InsuranceRule.AddRule("insuranceId", "_id"); InsuranceRule.AddRule("name", "name"); MapRule InsurancePersonRule = new MapRule(Model.FindByName("Insurance"), Schema.FindByName("Person"), false); InsurancePersonRule.AddRule("insuranceId", "insuranceId"); MapRule RelationshipRule = new MapRule(Model.FindByName("HasInsurance"), Schema.FindByName("Person"), false); RelationshipRule.AddRule("insuranceValue", "insuranceValue"); ModelMapping Map = new ModelMapping("PersonCarMap", new List <MapRule> { PersonRule, CarRule, InsuranceRule, RelationshipRule, InsurancePersonRule }); return(new RequiredDataContainer(Model, Schema, Map)); }
/// <summary> /// Maps entities to collection and return all data (ERModel, MongoSchema and ModelMapping) /// </summary> /// <returns></returns> public static RequiredDataContainer MapEntitiesToCollections() { // Create schema MongoDBCollection UserCol = new MongoDBCollection("User"); UserCol.AddAttributes("_id", "UserName", "UserEmail"); MongoDBCollection ProductCol = new MongoDBCollection("Product"); ProductCol.AddAttributes("_id", "Title", "Description", "CategoryID", "StoreID", "UserID"); MongoDBCollection CategoryCol = new MongoDBCollection("Category"); CategoryCol.AddAttributes("_id", "CategoryName"); MongoDBCollection StoreCol = new MongoDBCollection("Store"); StoreCol.AddAttributes("_id", "StoreName"); MongoSchema Schema = new MongoSchema("CMSSchema", new List <MongoDBCollection>() { UserCol, ProductCol, StoreCol, CategoryCol }); // Retrieve ER Model ERModel Model = GetERModel(); // Build mapping Entity User = (Entity)Model.FindByName("User"); MapRule UserRules = new MapRule(User, UserCol); UserRules.AddRule("UserID", "_id"); UserRules.AddRule("UserName", "UserName"); UserRules.AddRule("UserEmail", "UserEmail"); Entity Product = (Entity)Model.FindByName("Product"); MapRule ProductRules = new MapRule(Product, ProductCol); ProductRules.AddRule("ProductID", "_id"); ProductRules.AddRule("Title", "Title"); ProductRules.AddRule("Description", "Description"); Entity Category = (Entity)Model.FindByName("Category"); MapRule CategoryRules = new MapRule(Category, CategoryCol); CategoryRules.AddRule("CategoryID", "_id"); CategoryRules.AddRule("CategoryName", "CategoryName"); Entity Store = (Entity)Model.FindByName("Store"); MapRule StoreRules = new MapRule(Store, StoreCol); StoreRules.AddRule("StoreID", "_id"); StoreRules.AddRule("StoreName", "StoreName"); MapRule UserProductRule = new MapRule(User, ProductCol, false); UserProductRule.AddRule("UserID", "UserID"); MapRule StoreProductRule = new MapRule(Store, ProductCol, false); StoreProductRule.AddRule("StoreID", "StoreID"); MapRule CategoryProductRule = new MapRule(Category, ProductCol, false); CategoryProductRule.AddRule("CategoryID", "CategoryID"); ModelMapping Map = new ModelMapping("CMSMap11", new List <MapRule>() { UserRules, ProductRules, CategoryRules, StoreRules, UserProductRule, StoreProductRule, CategoryProductRule }); return(new RequiredDataContainer(Model, Schema, Map)); }