コード例 #1
0
        private KindKeyInfo GetKindKeyInfo()
        {
            var properties = typeof(TEntity).GetProperties();
            var propertiesWithKeyAttributeCount = 0;
            var kindKeyInfo = new KindKeyInfo();

            foreach (var property in properties)
            {
                var keyAttribute = property.GetCustomAttribute <KindKeyAttribute>();
                if (keyAttribute != null)
                {
                    kindKeyInfo = new KindKeyInfo
                    {
                        IsAutoGenerated = keyAttribute.IsAutoGenerated,
                        KeyName         = property.Name
                    };
                    propertiesWithKeyAttributeCount++;
                }
            }

            if (propertiesWithKeyAttributeCount > 1)
            {
                var errorMsg = propertiesWithKeyAttributeCount > 1 ? "Too many keys defined - only one allowed." : "Missing required key attribute - make sure you've added KindKey attribute on one of the properties.";
                throw new Exception(errorMsg);
            }

            return(kindKeyInfo);
        }
コード例 #2
0
        protected DatastoreKindBase(DatastoreDb database, string entityPrefix)
        {
            _kindKeyInfo = GetKindKeyInfo();

            _database = database;
            _kind     = GetKind(entityPrefix);
        }