我认为解决方案是这样的,
var result = from t1 in table1
from t2 in table2
where condition // if there is any condition to fetch records
select new { address = t1.address, religion= t1.religion,columnN = t1.columnN, Name = t2.name };
更新
JsonConvert.SerializeObject() 使用 linq 将新创建的对象序列化为 json 并解决您面临的问题。
希望你喜欢我的回答
谢谢
class Employee
{
public string employeeID;
public string Name;
public string eventName;
public Employee(string eID, string eName, string eEvents)
{
this.employeeID = eID;
this.Name = eName;
this.eventName = eEvents;
}
}
class Event
{
public int id { get; set; }
public string name { get; set; }
public Event(int _id,string _name)
{
id = _id;
name = _name;
}
}
class Program
{
static void Main(string[] args)
{
List<Employee> employees = new List<Employee>();
employees.Add(new Employee("PALI_e1", "Parvez Ali", "FOOTBALL"));
employees.Add(new Employee("AALI_e2", "Ashik Ali", "FOOTBALL"));
employees.Add(new Employee("AALI_e3", "Aftab Ali", "CHESS"));
employees.Add(new Employee("AALI_e4", "Arif Ali", "CRICKET"));
List<Event> courses = new List<Event>();
courses.Add(new Event(1,"FOOTBALL"));
courses.Add(new Event(2,"FOOTBALL"));
var result = from l1 in employees
from l2 in courses
where l1.eventName == l2.name
select new { l1, l2.name };
string output = JsonConvert.SerializeObject(result);
Console.WriteLine(output);
}
}
Here is expected output screenshot