AddRange导致列表内容被更改

时间:2019-03-25 16:16:46

标签: c# linq

嗨,我在添加范围方面遇到问题,它似乎被我使用添加范围方法的列表中的第二项覆盖了

例如

我的订单表中有4个字段,可以很好地添加到我的列表中

第二遍 我的下一张表已添加到列表中,但显示的字段超出了应有的数量,并且该列表已满第二张表,第一个被覆盖了,我相信这可能是这里的问题

  _newPersistantObjectList.First().FieldsList.AddRange(_newFieldList);
private void genXmlSchema_Click(object sender, EventArgs e)
{
        List<TableDefnition> _fieldNameList = new List<TableDefnition>();
        PersistentObject _testObjects = new PersistentObject();
        List<GridViewRowInfo> _checkRows = GetCheckedRows(rgTableNames);
        List<PersistentObject> _fieldScehmasList = new List<PersistentObject>();
        _newPersistantObjectList = new List<PersistentObject>();
        int i = 0;
        foreach (GridViewRowInfo row in _checkRows)
        {
            i++;

            var currentRow = (TableNames)row.DataBoundItem;
            rgFieldsOfTable.DataSource = db.GetALLTableDeiniations(currentRow.TABLE_NAME);
            _fieldNameList.AddRange(db.GetALLTableDeiniations(currentRow.TABLE_NAME));                
            _fieldScehmasList.AddRange(BuildSchema(_fieldNameList, currentRow.TABLE_NAME));
        }

        _newPObject.PersistentObjects.AddRange(_fieldScehmasList);
        _newPObject.ClassPrefix = "Persistent";
        _newPObject.ClassSuffix = "";
        _newPObject.Language = "VB";
        _newPObject.Path = @"C:\Sage200SchemaExtensions";
        _newPObject.GenerateSeparateFiles = "false";
        _newPObject.GenerateBusinessObjects = "false";
        _newPObject.BaselineSchema = @"C:\Program Files (x86)\Sage 200 SDK\SageObjectStore.xml";
        _newPObject.DataTypes = "";
        _newPObject.Enumerations = "";
        _newPObject.MemberVariablePrefix = "_";
        _newPObject.ApplicationNamespace = "BusinessObjects";
        schemeContent.Text = HelperXml.ToXML(_newPObject);
    }

构建模式是我用来收集表中字段信息的方法。

    public List<PersistentObject> BuildSchema(List<TableDefnition> fieldList, string tableName)
    {
        _newPersistantObjectList.Clear();
        _newFieldList.Clear();
        _newObject.Name = tableName;
        foreach (var item in fieldList.Where(w=>w.TableName ==tableName).ToList())
        {

            FieldSchemaXml _newSchema = new FieldSchemaXml();


            _newSchema = ConvertSQLDataTypeToSage(item.Type, _newSchema, item);


            _newSchema.Name = item.Field;
            _newSchema.IsUnique = "false";
            _newSchema.IsReadOnly = "false";
            _newSchema.IsQueryable = "true";
            if (item.is_nullable == 1)
            {

                _newSchema.IsNullable = "true";
            }
            else
            {
                _newSchema.IsNullable = "false";
            }

            _newSchema.IsReadOnly = "false";
            _newSchema.IsUnique = "false";
            _newSchema.Group = "false";

            _newSchema.IsLockable = "false";
            _newSchema.IsDeltaField = "false";
            _newSchema.AllowOverwrite = "True";
            _newSchema.IsPrimaryKey = "false";
            _newSchema.Scale = "0";
            _newSchema.IsIndexed = "false";
            _newSchema.FillType = "None";
            _newSchema.Direction = "Input";
            _newSchema.OverrideFormatting = "false";
            _newSchema.ValueSetByDatabase = "false";
            _newSchema.FormatScale = "0";
            _newSchema.NegativeFormatting = "Standard";
            _newSchema.AggregateFunction = "None";
            _newSchema.ValueSetByDatabase = "false";
            _newSchema.IsExcludedFromCopy = "false";
            _newSchema.FriendlyName = "";

            _newSchema.IsTransient = "false";
            _newSchema.IsExpression = "false";
            _newSchema.IsBrowsable = "true";
            _newSchema.IsQueryable = "true";
            _newSchema.IsEnumeration = "false";
            _newSchema.IsAddInPrimaryKey = "false";
            _newSchema.IsExcludedFromReset = "false";
            _newSchema.IsMember = "false";
            _newSchema.AddInTableName = "";


            _newObject.IsCacheable = "false";

            _newObject.Description = "";


            _newObject.AllowZeroKeys = "false";
            _newObject.TransactionMode = "Required";
            _newObject.IsStoredProcedure = "false";
            _newObject.ProcedureReturnType = "";
            _newObject.AlwaysAllowPaging = "false";
            _newObject.Namespace = "";
            _newObject.Name = tableName;
            _newObject.PagingFields = "";

            _newFieldList.Add(_newSchema);

        }
        _newPersistantObjectList.Add(_newObject);
        _newPersistantObjectList.First().FieldsList.AddRange(_newFieldList);

        return _newPersistantObjectList;

    }

这是我的模式

public class SageXmlDefiniation
{

    [XmlRoot("ObjectStore", Namespace = "urn:SageObjectStore")]

     public class ObjectStore

        {
        [XmlIgnore]
        private  List<PersistentObject> _PersistentObject = new List<PersistentObject>();

        public string ApplicationNamespace { get; set; }
        public string MemberVariablePrefix { get; set; }
        public string ClassPrefix { get; set; }
        public string ClassSuffix { get; set; }
        public string Language { get; set; }
        public string Path { get; set; }
        public string GenerateBusinessObjects { get; set; }
        public string GenerateSeparateFiles { get; set; }

        public string NameSpace { get; set; }

        public List<PersistentObject> PersistentObjects
        {
            get { return _PersistentObject; }
            set { _PersistentObject = value; }
        }
        public string DataTypes
        {
            get; set;
        }
        public string Enumerations { get; set; }

        public string BaselineSchema { get; set; }



}
public class PersistentObject
    {
        private List<FieldSchemaXml> _Fields = new List<FieldSchemaXml>();

        [XmlAttribute("Name")]
        public string Name { get; set; }

        public string TableName { get; set; }
        public string Description { get; set; }
        [XmlArray("Fields")]
        [XmlArrayItem("Field")]
        public List<FieldSchemaXml> FieldsList
        {
            get { return _Fields; }
            set { _Fields = value; }
        }
        public string IsCacheable { get; set; }
        public string AllowZeroKeys { get; set; }
        public string AlwaysAllowPaging { get; set; }
        public string Namespace { get; set; }
        public string PagingFields { get; set; }
        public string TransactionMode { get; set; }
        public string IsStoredProcedure { get; set; }
        public string ProcedureReturnType { get; set; }



    }
    public class FieldSchemaXml
    {
        [XmlAttribute("Name")]
        public string Name { get; set; }

        public string DbType { get; set; }
        public string Precision { get; set; }
        public string Scale { get; set; }
        public string FillType { get; set; }
        public string IsNullable { get; set; }
        public string IsReadOnly { get; set; }
        public string AllowOverwrite { get; set; }
        public string IsPrimaryKey { get; set; }

        public string IsDeltaField { get; set; }
        public string IsIndexed { get; set; }
        public string IsTransient { get; set; }
        public string IsUnique { get; set; }

        public string OverrideFormatting { get; set; }
        public string IsLockable { get; set; }
        public string Direction { get; set; }
        public string ValueSetByDatabase { get; set; }
        public string FormatScale { get; set; }
        public string FormatMask { get; set; }
        public string NegativeFormatting { get; set; }
        public string Group { get; set; }
        public string AggregateFunction { get; set; }
        public string IsExcludedFromCopy { get; set; }
        public string IsExpression { get; set; }
        public string FriendlyName { get; set; }
        public string IsBrowsable { get; set; }
        public string IsQueryable { get; set; }
        public string IsEnumeration { get; set; }

        public string IsAddInPrimaryKey { get; set; }
        public string AddInTableName { get; set; }
        public string AddInRelationField { get; set; }
        public string IsMember { get; set; }
        public string IsExcludedFromReset { get; set; }

    }

 }

我创建了一个小jinq视频供您查看问题。

https://www.screencast.com/t/iJIBzVo7hKNc

0 个答案:

没有答案