Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从两个列表中使用LINQ构建列表_Linq_List - Fatal编程技术网

从两个列表中使用LINQ构建列表

从两个列表中使用LINQ构建列表,linq,list,Linq,List,我有两份清单: 列表1={A',B',C',D',E',F',G',H',I',J',K'} 列表2={B',C',D'} List1是表中的所有列,List2是构成同一表上外键或主键的列 在本例中,“A”、“B”、“C”和“D”是表的主键“B”、“C”和“D”是同一个表的外键。”G'和H'是我不想包含的表的两列 我似乎无法编写一个LINQ语句来生成以下内容: 清单3={B',C',D',E',F',I',J',K'} List3是我想要给我正在生成的更新存储过程的参数列表。List2+'K'将

我有两份清单:

列表1={A',B',C',D',E',F',G',H',I',J',K'}

列表2={B',C',D'}

List1是表中的所有列,List2是构成同一表上外键或主键的列

在本例中,“A”、“B”、“C”和“D”是表的主键“B”、“C”和“D”是同一个表的外键。”G'和H'是我不想包含的表的两列

我似乎无法编写一个LINQ语句来生成以下内容:

清单3={B',C',D',E',F',I',J',K'}

List3是我想要给我正在生成的更新存储过程的参数列表。List2+'K'将是我的WHERE;'E、F、I和J将是程序在集合中使用的列

每次执行LINQ时,列表1和列表2都将不同

所有列表均为List类型,其中DbColumn定义为:

public class DbColumn
{
    public string Name { get; set; }
    //public bool IsPrimaryKey { get; set; }
    //public bool IsForeignKey { get; set; }
    public int OrdinalPosition { get; set; }
    public string DataType { get; set; }
    public int CharMaxLength { get; set; }
    public bool AllowNulls { get; set; }

    public static DbColumn Create(string name, int ordinal_position, string data_type, int charMaxLength, string is_nullable)
    {
        DbColumn column = new DbColumn();

        column.Name = name;
        //column.IsPrimaryKey = isPk;
        //column.IsForeignKey = isFk;
        column.OrdinalPosition = ordinal_position;
        column.DataType = data_type;
        column.CharMaxLength = charMaxLength;

        if (!String.IsNullOrEmpty(is_nullable))
            column.AllowNulls = is_nullable.ToUpper() == "YES" ? true : false;
        else
            column.AllowNulls = false;

        return column;
    }

    public override string ToString()
    {
        return Name;
    }
}
列可以是DbConstraint和DbTable的一部分。DbTable还将DbConstraint作为属性:

public class DbTable
{
    public string Name { get; set; }
    public string Catalog { get; set; }
    public string Schema { get; set; }
    public List<DbColumn> Columns { get; set; }
    public DbSProc Insert { get; set; }
    public DbSProc Update { get; set; }
    public DbSProc Delete { get; set; }
    public List<DbSProc> ReadProcedures { get; set; }
    public List<DbConstraint> Constraints { get; set; }

    public static DbTable Create(string name, string catalog, string schema, List<DbColumn> columns)
    {
        DbTable table = new DbTable();

        table.Catalog = catalog;
        table.Schema = schema;
        table.Name = name;
        table.Columns = columns;
        table.ReadProcedures = new List<DbSProc>();

        return table;
    }

    public override string ToString()
    {
        return Name;
    }
}

public class DbConstraint
{
    public string Name { get; set; }
    public bool IsPrimary { get; set; }
    public List<DbColumn> Columns { get; set; }

    public static DbConstraint Create(string name, bool isPrimary)
    {
        DbConstraint constraint = new DbConstraint();
        constraint.Name = name;
        constraint.IsPrimary = isPrimary;
        constraint.Columns = new List<DbColumn>();

        return constraint;
    }

    public override string ToString()
    {
        return Name;
    }
}
LINQ语句的目标是仅为参数选择WHERE块所需的列,例如:外键/主键加上_VerCol,以及设置块非主键所需的列

您可以在CodePlex上找到代码:

有人能帮我吗


谢谢大家!

我假设您知道要排除的字符

List<char> a = new List<char>() { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K' };
List<char> b = new List<char>() { 'B', 'C', 'D' };
List<char> exclusionList = new List<char> {'A','G', 'H'};

List<char> c = a.Select(x => x).Where(x => !exclusionList.Contains(x)).ToList();

您没有解释从列表1和列表2到列表3的逻辑。当列表2中的第一个条目出现时,您是否从列表1中获取条目?你认为列表1中的所有条目都比列表2中最小的条目大吗?我感谢你更新你的问题,但你真的需要更好地解释它。您似乎要处理的不仅仅是三个列表。您能明确描述什么是列表1和列表2吗?我们怎么知道G和H是特殊的呢?我们怎么知道A是特别的而E、F、I、J和K不是?@Enigmativity-谢谢。我真的不想谈太多细节,因为我认为人们会感到困惑,问题可能会在对话中消失。我在CodePlex中有一个项目,它叫SqlMeth:。在Hallucinator.cs中,该过程的名称为GenerateSpecificUpdateSprocs。问题是生成可枚举参数。我会补充更多关于这个问题的信息。@Jaquio-人们对缺乏细节感到困惑。而且,即使您现在已经添加了类,您仍然没有明确定义List1和List2是什么。我知道它们都是列表,但您还没有解释它们之间的关系,以及我们如何根据列表1和列表2中的值确定要保留哪些列以及要放弃哪些列。在这里提问最重要的部分是花时间写一个好问题,使回答尽可能容易。你还没有做到。写下我想做的事情的目标帮助我找到了问题的答案。我修改了代码,将主键从表列列表1中排除,然后只在存储过程列表2中添加所需的键。这让我注意到另一个问题:Contains没有正确地计算对象。在覆盖Equals之后,一切似乎都运转良好@神秘性——我会为下次写更好的问题;谢谢,这在一定程度上帮助了我。在我的情况下,覆盖平等也是必要的。