private static IUniquelyDeterminedObject CreateInstance(System.Type type, object id)
        {
            if (type == typeof(Template))
            {
                if (id.ToString().Contains("AttributesTemplate"))
                {
                    var instance = RunTimeTemplates.GetRuntimeTemplate(id.ToString());

                    addRemoveTypes(type, id);

                    objects[type].Add(instance);

                    instance.Changed += new EventHandler(instance_Changed);

                    return(instance);
                }
                else
                {
                    using (var c = new SqlConnection(ConnectionString))
                    {
                        var query    = String.Format("SELECT [Model].[XMLTemplate]({0})", id);
                        var reader   = ExecuteScalarStringReader(query);
                        var e        = XElement.Load(reader);
                        var parser   = new TemplateParser();
                        var instance = parser.Parse(e);

                        addRemoveTypes(type, id);

                        objects[type].Add(instance);

                        instance.Changed += new EventHandler(instance_Changed);

                        return(instance);
                    }
                }
            }
            else if (type == typeof(EntityFilter))
            {
                using (var c = new SqlConnection(ConnectionString))
                {
                    var query  = String.Format("SELECT model.xmlEntityFilter({0})", id);
                    var reader = ExecuteScalarStringReader(query);

                    var e      = XElement.Load(reader);
                    var parser = new EntityFilterParser();

                    var instance = parser.Parse(e);

                    addRemoveTypes(type, id);

                    objects[type].Add(instance);

                    instance.Changed += new EventHandler(instance_Changed);

                    return(instance);
                }
            }
            else if (type == typeof(BusinessContent))
            {
                var entity = Storage.Select <Entity>(id);

                using (var c = new SqlConnection(ConnectionString))
                {
                    var query = String.Format("EXEC [report].[getBObjectData] @baseTable={0}, @flFormat = 0, @flheader = 0", id);

                    var dt = GetDataTable(query);

                    var instance = new BusinessContent(id, entity.Name, dt);

                    addRemoveTypes(type, id);

                    objects[type].Add(instance);

                    instance.Changed += new EventHandler(instance_Changed);

                    BusinessContentIsChanged = true;

                    return(instance);
                }
            }
            else
            {
                throw new InvalidOperationException(
                          string.Format("Текущий провайдер не обеспечивает выборку элементов типа {0}.", type.FullName));
            }
        }