Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/294.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
C# 从多个不相交的表查询数据(EF6)_C#_Entity Framework - Fatal编程技术网

C# 从多个不相交的表查询数据(EF6)

C# 从多个不相交的表查询数据(EF6),c#,entity-framework,C#,Entity Framework,我目前正在尝试自动执行搜索任务。基本上,我有多个这样的表: var result = tableAs.Select(e => (e.PartNumber, e.Value)) .Union(tableBs.Select(e => (e.PartNumber, e.Value))) .Union(tableCs.Select(e => (e.PartNumber, e.Value))) .Where(e => e.PartNumber.Contain

我目前正在尝试自动执行搜索任务。基本上,我有多个这样的表:

var result = tableAs.Select(e => (e.PartNumber, e.Value))
    .Union(tableBs.Select(e => (e.PartNumber, e.Value)))
    .Union(tableCs.Select(e => (e.PartNumber, e.Value)))
    .Where(e => e.PartNumber.Contains("something") || e.Value.Contains("something else"))
    .ToList();
  • 包含以下列的表格:Id、零件号、值、R
  • 带列的表B:Id、零件号、值、C
  • 带列的表C:Id、零件号、值、X
基本上是多个非常相似的表。我现在要做的是,在“PartNumber”和“Value”字段中搜索文本字符串。我不介意它是否出现在R、C、X列中

有办法去吗

  • 查询存在哪些表名
  • 然后对每个表执行相同的查询
  • 连接结果(我不介意列表中的类型是否不同,或者它是否成为新类型)
  • 如果添加了新表,则只应将其添加到上下文中,然后自动进行搜索。

    假设您已经

    class TableA
    {
        public int Id { get; set; }
        public string PartNumber { get; set; }
        public string Value { get; set; }
        public int R { get; set; }
    }
    
    class TableB
    {
        public int Id { get; set; }
        public string PartNumber { get; set; }
        public string Value { get; set; }
        public int C { get; set; }
    }
    
    class TableC
    {
        public int Id { get; set; }
        public string PartNumber { get; set; }
        public string Value { get; set; }
        public int X { get; set; }
    }
    
    List<TableA> tableAs = new List<TableA>();
    List<TableB> tableBs = new List<TableB>();
    List<TableC> tableCs = new List<TableC>();