/// <summary>
        /// Converting to foundation type
        /// </summary>
        /// <param name="catalog"></param>
        /// <returns></returns>
        public static dataModel.CatalogBase ToDataModel(this coreModel.Catalog catalog)
        {
            if (catalog == null)
            {
                throw new ArgumentNullException("catalog");
            }

            if (catalog.DefaultLanguage == null)
            {
                throw new NullReferenceException("DefaultLanguage");
            }

            dataModel.CatalogBase    retVal;
            dataModel.Catalog        dbCatalog     = null;
            dataModel.VirtualCatalog dbVirtCatalog = null;

            if (catalog.Virtual)
            {
                dbVirtCatalog = new dataModel.VirtualCatalog();
                retVal        = dbVirtCatalog;
            }
            else
            {
                dbCatalog = new dataModel.Catalog();

                if (catalog.PropertyValues != null)
                {
                    dbCatalog.CatalogPropertyValues = new ObservableCollection <dataModel.CatalogPropertyValue>();
                    dbCatalog.CatalogPropertyValues.AddRange(catalog.PropertyValues.Select(x => x.ToDataModel <dataModel.CatalogPropertyValue>()).OfType <dataModel.CatalogPropertyValue>());
                }
                retVal = dbCatalog;
            }

            //Because EF mapping schema not automatically linked foreign keys, we should generate manually id and  set links manually
            var id = retVal.Id;

            retVal.InjectFrom(catalog);
            if (catalog.Id == null)
            {
                retVal.Id = id;
            }

            retVal.DefaultLanguage = catalog.DefaultLanguage.LanguageCode;

            if (dbCatalog != null && catalog.Languages != null)
            {
                dbCatalog.CatalogLanguages = new ObservableCollection <dataModel.CatalogLanguage>();
                foreach (var dbCatalogLanguage in catalog.Languages.Select(x => x.ToDataModel()))
                {
                    dbCatalogLanguage.CatalogId = retVal.Id;
                    dbCatalog.CatalogLanguages.Add(dbCatalogLanguage);
                }
            }

            retVal.Name = catalog.Name;

            return(retVal);
        }
        /// <summary>
        /// Converting to foundation type
        /// </summary>
        /// <param name="catalog"></param>
        /// <returns></returns>
        public static dataModel.CatalogBase ToDataModel(this coreModel.Catalog catalog)
        {
            if (catalog == null)
                throw new ArgumentNullException("catalog");

			if(catalog.DefaultLanguage == null)
				throw new NullReferenceException("DefaultLanguage");

            dataModel.CatalogBase retVal;
            dataModel.Catalog dbCatalog = null;
            dataModel.VirtualCatalog dbVirtCatalog = null;

            if (catalog.Virtual)
            {
                dbVirtCatalog = new dataModel.VirtualCatalog();
                retVal = dbVirtCatalog;
            }
            else
            {
                dbCatalog = new dataModel.Catalog();

                if (catalog.PropertyValues != null)
                {
                    dbCatalog.CatalogPropertyValues = new ObservableCollection<dataModel.CatalogPropertyValue>();
                    dbCatalog.CatalogPropertyValues.AddRange(catalog.PropertyValues.Select(x => x.ToDataModel<dataModel.CatalogPropertyValue>()).OfType<dataModel.CatalogPropertyValue>());
                }
                retVal = dbCatalog;
            }

            //Because EF mapping schema not automatically linked foreign keys, we should generate manually id and  set links manually
            var id = retVal.Id;
            retVal.InjectFrom(catalog);
            if (catalog.Id == null)
            {
                retVal.Id = id;
            }

			retVal.DefaultLanguage = catalog.DefaultLanguage.LanguageCode;

            if (dbCatalog != null && catalog.Languages != null)
            {
                dbCatalog.CatalogLanguages = new ObservableCollection<dataModel.CatalogLanguage>();
                foreach (var dbCatalogLanguage in catalog.Languages.Select(x => x.ToDataModel()))
                {
                    dbCatalogLanguage.CatalogId = retVal.Id;
                    dbCatalog.CatalogLanguages.Add(dbCatalogLanguage);
                }
            }

            retVal.Name = catalog.Name;

            return retVal;
        }