CSharp · Console
using System;
using System.Collections.Generic;
using System.Linq;
public class Program
{
public static void Main()
{
var docs = new List<Doc>()
{
new Doc(1, "C:\\Files\\A.txt"),
new Doc(2, "C:\\Files\\B.txt"),
new Doc(3, "C:\\Files\\C.txt"),
};
var users = new List<User>()
{
new User(1, "Adam"),
new User(2, "Benny"),
new User(3, "Charlie"),
};
var dus = new List<Doc_User>()
{
new Doc_User(1,1),
new Doc_User(1,2),
new Doc_User(2,1),
new Doc_User(2,2),
new Doc_User(2,3)
};
var db = new DB() { Docs = docs, Users = users, DU = dus };
var model = (from d in db.Docs
join du in db.DU on d.Id equals du.DocId
join u in db.Users on du.UserId equals u.Id
select new DataModel() { DocPath = d.Path, UserName = u.Name }).ToList();
foreach(var item in model)
{
Console.WriteLine(item.DocPath + " | " + item.UserName);
}
}
}
public class DB
{
public List<Doc> Docs {get; set;}
public List<User> Users {get; set;}
public List<Doc_User> DU {get; set;}
}
public class Doc
{
public Doc(int id, string path)
{
Id = id;
Path = path;
}
public int Id {get; set;}
public string Path {get; set;}
}
public class User
{
public User(int id, string name)
{
Id = id;
Name = name;
}
public int Id {get; set;}
public string Name {get; set;}
}
public class Doc_User
{
public Doc_User(int idD, int idU)
{
DocId = idD;
UserId = idU;
}
public int DocId {get; set;}
public int UserId {get;set;}
}
public class DataModel
{
public string DocPath {get; set;}
public string UserName {get; set;}
}