Esempio n. 1
0
        private static void Main()
        {
            var dbContextFactory     = new KandandaDatabaseContextFactory();
            var pluralizationService = new EnglishPluralizationService();

            var tournamentRepository  = new TournamentRepository(dbContextFactory, pluralizationService);
            var participantRepository = new ParticipantRepository(dbContextFactory, pluralizationService);

            var newTournament = new Tournament
            {
                Name = "Schweizermeisterschaft"
            };

            var newParticipant = new Participant
            {
                Name = "FC St. Gallen"
            };

            newTournament.Participants.Add(newParticipant);
            tournamentRepository.Save(newTournament);

            List <Participant> participants = participantRepository.GetAll();

            foreach (Participant participant in participants)
            {
                Console.WriteLine($"{participant.Id} {participant.Name}");
            }

            Console.ReadKey();
        }
        static EntityDesignUtil()
        {
            PluralizationService =
                new EnglishPluralizationService();
            KnownPlural =
                new Dictionary <string, string>();
            KnownSingular =
                new Dictionary <string, string>();
            SingularToPlural =
                new Dictionary <string, string>();
            PluralToSingular =
                new Dictionary <string, string>();
            var mappings = TemplateConstants
                           .PluralizationMappings
                           .Split(',');

            for (var i = 0; i < mappings.Length; i += 2)
            {
                var map0 = mappings[i].Trim();
                var map1 = mappings[i + 1].Trim();
                KnownPlural.Add(map1, map1);
                KnownSingular.Add(map0, map0);
                SingularToPlural.Add(map0, map1);
                PluralToSingular.Add(map1, map0);
            }
        }
        public void Pluralize_userdictionary_override_default_rules()
        {
            var entries = new[]
            {
                new CustomPluralizationEntry(singular: "X", plural: "Z")
            };
            var pluralizationService = new EnglishPluralizationService(entries);

            Assert.Equal("Z", pluralizationService.Pluralize("X"));
        }
Esempio n. 4
0
        public static string Pluralize(this string source)
        {
            if (string.IsNullOrWhiteSpace(source))
            {
                return(string.Empty);
            }
            source = source.TitleCase();
            var    ps      = new EnglishPluralizationService();
            var    match   = new Regex(@"([A-Z]+[^A-Z]*)$").Match(source);
            string ending  = match.Groups.Count > 0 ? match.Groups[0].Value : source;
            string pEnding = ps.Pluralize(ending);

            return(source.Substring(0, source.Length - ending.Length) + pEnding);
        }
Esempio n. 5
0
        public void EnglishPluralizationServiceTest()
        {
            IncrementTestCount();
            var service = new EnglishPluralizationService();
            var pears   = service.Pluralize("pear");
            var pear    = service.Singularize("pears");

            service.Pluralize("apple");
            service.Singularize("apples");
            service.Pluralize("monkey");
            service.Singularize("monkies");

            Assert.AreEqual("pear", pear);
            Assert.AreEqual("pears", pears);
        }
Esempio n. 6
0
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            const string SingularEntityText = "Entity";

            EnglishPluralizationService pluralizer = new EnglishPluralizationService();

            modelBuilder.Types().Where(type => type.Name.EndsWith(SingularEntityText)).Configure(c =>
            {
                string clrTypeName = c.ClrType.Name;
                string entityName  = clrTypeName.Substring(0, clrTypeName.Length - SingularEntityText.Length);
                c.ToTable(pluralizer.Pluralize(entityName));
            });

            base.OnModelCreating(modelBuilder);
        }
        internal static void RemoveSuffixFromTheTableNames(this DbModelBuilder modelBuilder, string suffix)
        {
            if (string.IsNullOrWhiteSpace(suffix))
            {
                return;
            }

            EnglishPluralizationService pluralizer = new EnglishPluralizationService();

            modelBuilder.Types().Where(type => type.Name.EndsWith(suffix)).Configure(c =>
            {
                string clrTypeName = c.ClrType.Name;
                string entityName  = clrTypeName.Substring(0, clrTypeName.Length - suffix.Length);
                c.ToTable(pluralizer.Pluralize(entityName));
            });
        }
Esempio n. 8
0
        public static IEnumerable <IFigure> GetRelationship(Stock stock, Type figureType)
        {
            var service        = new EnglishPluralizationService();
            var collectionName = service.Pluralize(figureType.Name);

            var property = typeof(Company).GetProperty(collectionName);

            if (property != null)
            {
                return((IEnumerable <IFigure>)property.GetValue(stock.Company));
            }

            property = typeof(Stock).GetProperty(collectionName);
            if (property != null)
            {
                return((IEnumerable <IFigure>)property.GetValue(stock));
            }

            throw new ArgumentException(string.Format("No relationship (navigation property) found with name {0} on Company or Stock", collectionName));
        }
        /// <summary>
        /// Generic Method to initialize the gridview
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="gridView"></param>
        /// <param name="columnsToHide"></param>
        private void InitializeDataGridView <T>(DataGridView gridView, DataSet dataSet, params string[] columnsToHide) where T : class
        {
            // Set up gridview
            gridView.AllowUserToAddRows    = false;
            gridView.AllowUserToDeleteRows = false;
            gridView.ReadOnly            = true;
            gridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;

            /*            // Set event handler to delete row
             *          gridView.UserDeletingRow += (s, e) => DeletingRow<T>(s as DataGridView, e);*/

            // Binding the data
            gridView.DataSource = Controller <BeautySalonEntities, T> .SetBindingList();

            foreach (string column in columnsToHide)
            {
                gridView.Columns[column].Visible = false;
            }

            string tableName;

            switch (typeof(T).Name)
            {
            case "Inventory":
                tableName = "Inventory";
                break;

            case "AppointmentsView":
                tableName = "AppointmentsView";
                break;

            default:
                EnglishPluralizationService pluralize = new EnglishPluralizationService();
                tableName = pluralize.Pluralize(typeof(T).Name);
                break;
            }

            DataTable table = beautySalonDB.GetDataTable(tableName);

            dataSet.Tables.Add(table);
        }
        public OapTablePrefixConvention()
        {
            string prefix = "Oap_";
            var    myList = new List <string>();

            try
            {
                var plural = new EnglishPluralizationService();

                //TODO: Modify this to use a custom attribute to not apply this default convention.
                Types().Where(t => !t.CustomAttributes.Any(ca => ca.AttributeType == (typeof(NonOapEntity)))).Configure(c =>
                {
                    var tableName = plural.Pluralize($"{prefix}{c.ClrType.Name}s");
                    c.ToTable(tableName);
                    myList.Add(tableName);
                });
            }
            catch (System.Exception)
            {
                throw;
            }
        }
 static StringBuilder()
 {
     Code = new CodeGenerationTools();
     PluralizationService = new EnglishPluralizationService();
 }
Esempio n. 12
0
        public static void AddObject <TEntity>(this DataServiceContext dataServiceContext, TEntity entity)
        {
            var entitySetName = new EnglishPluralizationService().Pluralize(typeof(TEntity).Name);

            dataServiceContext.AddObject(entitySetName, entity);
        }
Esempio n. 13
0
        /// <summary>
        /// Pluralize given word
        /// </summary>
        /// <param name="word"></param>
        /// <returns>Pluralized word</returns>
        private string Pluralize(string word)
        {
            var pluraizationService = new EnglishPluralizationService();

            return(pluraizationService.Pluralize(word));
        }
Esempio n. 14
0
        public static string GetTableName(Type figureType)
        {
            var service = new EnglishPluralizationService();

            return(service.Pluralize(figureType.Name));
        }