예제 #1
0
        public EntityRecord GetEntityRecord(string uniqueRelationshipName, List <string> secondaryKeyValues)
        {
            if (String.IsNullOrWhiteSpace(uniqueRelationshipName))
            {
                throw new Exception("Unique relationship name is missing or empty.");
            }

            if (secondaryKeyValues == null || secondaryKeyValues.Count == 0)
            {
                throw new Exception("At least one secondary key values is required.");
            }

            var entityBatch = EntityBatches.Where(d => d.EntityDefinition.UniqueRelationshipName == uniqueRelationshipName).FirstOrDefault();

            if (entityBatch == null)
            {
                throw new Exception(string.Format("Entity batch with relationship name '{0}' does not exist.", uniqueRelationshipName));
            }

            var secondaryKeysCombo = new RecordKeyCombo(secondaryKeyValues);

            if (entityBatch.SecondaryKeys.ContainsKey(secondaryKeysCombo))
            {
                return(entityBatch.SecondaryKeys[secondaryKeysCombo]);
            }
            else
            {
                throw new Exception(string.Format("No entity record exists for relationship name '{0}' and secondary keys '{1}'.",
                                                  uniqueRelationshipName, StringHelper.GetDelimitedString(secondaryKeyValues, "','")));
            }
        }
예제 #2
0
        public bool ContainsKey(string uniqueRelationshipName, List <string> secondaryKeyValues)
        {
            if (String.IsNullOrWhiteSpace(uniqueRelationshipName))
            {
                throw new Exception("Unique relationship name is missing or empty.");
            }

            if (secondaryKeyValues == null || secondaryKeyValues.Count == 0)
            {
                throw new Exception("At least one secondary key values is required.");
            }

            var entityBatch = EntityBatches.Where(d => d.EntityDefinition.UniqueRelationshipName == uniqueRelationshipName).FirstOrDefault();

            if (entityBatch == null)
            {
                throw new Exception(string.Format("Entity batch with relationship name '{0}' does not exist.", uniqueRelationshipName));
            }

            var secondaryKeysCombo = new RecordKeyCombo(secondaryKeyValues);

            if (entityBatch.SecondaryKeys.ContainsKey(secondaryKeysCombo))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #3
0
        private void AddRecordToPrimaryKeysLookup <T>(EntityRecord record)
        {
            var primaryKeyCombo = new RecordKeyCombo(record.PrimaryKeyValues.ToList());

            try
            {
                PrimaryKeys.Add(primaryKeyCombo, record);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("An item of type {0} already exists for primary keys '{1}' with value(s): {2}.",
                                                  typeof(T).Name,
                                                  StringHelper.GetDelimitedString(record.AssociatedEntityBatch.EntityDefinition.PrimaryKeyColumnNames),
                                                  primaryKeyCombo.ToString()), ex);
            }
        }
예제 #4
0
        private void AddRecordToSecondaryKeysLookup <T>(EntityRecord record)
        {
            var secondaryKeys = record.SecondaryKeyValues;

            if (secondaryKeys != null && secondaryKeys.Count > 0)
            {
                var secondaryKeyCombo = new RecordKeyCombo(secondaryKeys);

                try
                {
                    SecondaryKeys.Add(secondaryKeyCombo, record);
                }
                catch (Exception ex)
                {
                    throw new Exception(string.Format("An item of type {0} already exists for secondary keys '{1}' with value(s): {2}.",
                                                      typeof(T).Name,
                                                      StringHelper.GetDelimitedString(record.AssociatedEntityBatch.EntityDefinition.PrimaryKeyColumnNames),
                                                      secondaryKeyCombo.ToString()), ex);
                }
            }
        }
예제 #5
0
        public static RecordKeyCombo GetRecordKeyComboFromDataRow(DataRow row, List <string> keyColumnNames)
        {
            if (keyColumnNames == null || keyColumnNames.Count == 0)
            {
                throw new Exception("At least one key column name is required.");
            }

            var recordKeyCombo = new RecordKeyCombo((row.Field <object>(keyColumnNames[0]) ?? "").ToString());

            if (keyColumnNames.Count == 1)
            {
                return(recordKeyCombo);
            }

            if (keyColumnNames.Count >= 2)
            {
                recordKeyCombo.Key2 = (row.Field <object>(keyColumnNames[1]) ?? "").ToString();
            }
            else
            {
                return(recordKeyCombo);
            }

            if (keyColumnNames.Count >= 3)
            {
                recordKeyCombo.Key3 = (row.Field <object>(keyColumnNames[2]) ?? "").ToString();
            }
            else
            {
                return(recordKeyCombo);
            }

            if (keyColumnNames.Count >= 4)
            {
                recordKeyCombo.Key4 = (row.Field <object>(keyColumnNames[3]) ?? "").ToString();
            }
            else
            {
                return(recordKeyCombo);
            }

            if (keyColumnNames.Count >= 5)
            {
                recordKeyCombo.Key5 = (row.Field <object>(keyColumnNames[4]) ?? "").ToString();
            }
            else
            {
                return(recordKeyCombo);
            }

            if (keyColumnNames.Count >= 6)
            {
                recordKeyCombo.Key6 = (row.Field <object>(keyColumnNames[5]) ?? "").ToString();
            }
            else
            {
                return(recordKeyCombo);
            }

            if (keyColumnNames.Count >= 7)
            {
                recordKeyCombo.Key7 = (row.Field <object>(keyColumnNames[6]) ?? "").ToString();
            }
            else
            {
                return(recordKeyCombo);
            }

            if (keyColumnNames.Count > 7)
            {
                throw new Exception("Support for more than 7 keys is not implemented.");
            }

            return(recordKeyCombo);
        }