• Как выбрать отличающиеся данные из БД с помощью Entity Framework?

    @smozhaykin
    class Employee
    {
    	public int Id { get; set; }
    	public string Name { get; set; }
    	public int CompanyId { get; set; }
    	
    	public override string ToString()
    	{
    		return string.Format("Employee Id = {0}, Name = {1}, CompanyId = {2}", Id, Name, CompanyId);
    	}
    }
    
    void Main()
    {
    	var employees = new Employee[] {
    	    new Employee() {Id = 1, Name = "Tim", CompanyId = 1111111},
    	    new Employee() {Id = 2, Name = "Jack", CompanyId = 126555},
    	    new Employee() {Id = 3, Name = "Tim", CompanyId = 1111111},
    	    new Employee() {Id = 4, Name = "Kris", CompanyId = 59911919},
    	    new Employee() {Id = 5, Name = "Tim", CompanyId = 1111111},
    	    new Employee() {Id = 6, Name = "John", CompanyId = 1111111},
    	    new Employee() {Id = 7, Name = "Kim", CompanyId = 1111111},
    	    new Employee() {Id = 8, Name = "Clark", CompanyId = 9984848},
    	};
    	
    	var filtered = from emp in employees group emp by emp.CompanyId into g where g.Count() == 1 select g.FirstOrDefault();
    	
    	foreach (var emp in filtered)
    	{
    	    Console.WriteLine(emp);
    	}
    }
    Ответ написан
    Комментировать