public static DecodedEntityClass GetEntityInfoThrowExceptionIfNotThere(this DbContext context, Type entityOrDto)
        {
            //If the entity type is found in the LinkToEntity interface it returns that, otherwise the called type because it must be the entity
            var entityType = entityOrDto.GetLinkedEntityFromDto() ?? entityOrDto;

            if (!EntityInfoCache.TryGetValue(entityType, out var result))
            {
                throw new InvalidOperationException(
                          $"The class {entityType.Name} is not registered as entity class in your DbContext {context.GetType().Name}.");
            }
            return(result);
        }
Example #2
0
 public void EntityRegistrationException_EntityWithoutDefaultConstructor_ShouldFail()
 {
     try
     {
         var cache = new EntityInfoCache(new DbGateConfig());
         cache.Register(typeof(EntityWithAllWrong));
         Assert.Fail("could register class without default constructor");
     }
     catch (EntityRegistrationException)
     {
         Assert.IsTrue(true, "could not register class without default constructor");
     }
     catch (System.Exception e)
     {
         Assert.Fail("unexpected exception" + e.Message);
     }
 }
 public static DecodedEntityClass GetRegisteredEntityInfo(this Type entityType)
 {
     return(EntityInfoCache.ContainsKey(entityType) ? EntityInfoCache[entityType] : null);
 }