Пример #1
0
        private void WriteKeys(XmlSchema schema, XmlSchemaElement element, CremaDataTable dataTable)
        {
            if (dataTable.PrimaryKey.Any() == false)
            {
                return;
            }

            var key = new XmlSchemaKey()
            {
                Name     = dataTable.KeyTypeName,
                Selector = new XmlSchemaXPath()
            };

            key.Selector.XPath = dataTable.GetSelectorXPath(CremaSchema.TableTypePrefix, schema.TargetNamespace);

            foreach (var item in dataTable.PrimaryKey)
            {
                var field = new XmlSchemaXPath()
                {
                    XPath = CremaSchema.TableTypePrefix + ":" + item.ColumnName
                };
                key.Fields.Add(field);
            }

            element.Constraints.Add(key);
        }
Пример #2
0
        private void WriteUniques(XmlSchema schema, XmlSchemaElement element, CremaDataTable dataTable)
        {
            foreach (var item in dataTable.Columns)
            {
                if (item.Unique == false)
                {
                    continue;
                }

                if (item.IsKey == true && dataTable.PrimaryKey.Length == 1)
                {
                    continue;
                }

                var unique = new XmlSchemaUnique()
                {
                    Name     = dataTable.Name + "." + item.ColumnName + "." + "Unique",
                    Selector = new XmlSchemaXPath()
                };
                unique.Selector.XPath = dataTable.GetSelectorXPath(CremaSchema.TableTypePrefix, schema.TargetNamespace);

                var field = new XmlSchemaXPath()
                {
                    XPath = CremaSchema.TableTypePrefix + ":" + item.ColumnName
                };
                unique.Fields.Add(field);
                element.Constraints.Add(unique);
            }
        }
Пример #3
0
        private void WriteUniques(XmlSchema schema, XmlSchemaElement element, CremaDataTable dataTable)
        {
            //var query = from item in dataTable.Columns
            //            where item.Unique == true
            //            select item;

            //if (query.Any() == false)
            //    return;

            //var unique = new XmlSchemaUnique()
            //{
            //    Name = dataTable.UniqueTypeName,
            //    Selector = new XmlSchemaXPath()
            //};
            //unique.Selector.XPath = dataTable.GetSelectorXPath(CremaSchema.TableTypePrefix, schema.TargetNamespace);

            //foreach (var item in query)
            //{
            //    var field = new XmlSchemaXPath()
            //    {
            //        XPath = CremaSchema.TableTypePrefix + ":" + item.ColumnName
            //    };
            //    unique.Fields.Add(field);
            //}
            //element.Constraints.Add(unique);

            foreach (var item in dataTable.Columns)
            {
                if (item.Unique == false)
                {
                    continue;
                }

                if (item.IsKey == true && dataTable.PrimaryKey.Length == 1)
                {
                    continue;
                }

                var unique = new XmlSchemaUnique()
                {
                    Name     = dataTable.Name + "." + item.ColumnName + "." + "Unique",
                    Selector = new XmlSchemaXPath()
                };
                unique.Selector.XPath = dataTable.GetSelectorXPath(CremaSchema.TableTypePrefix, schema.TargetNamespace);

                var field = new XmlSchemaXPath()
                {
                    XPath = CremaSchema.TableTypePrefix + ":" + item.ColumnName
                };
                unique.Fields.Add(field);
                element.Constraints.Add(unique);
            }
        }