У меня есть следующая реализация моего класса данных:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using static iText.StyledXmlParser.Jsoup.Select.Evaluator;
namespace WebApi.Entities
{
public class AgentTask : IEquatable, IComparable
{
[DefaultValue("1")]
[Key]
public int FunctionId { get; set; }
public string PreferredTime { get; set; }
public string UserFunction { get; set; }
public string Group { get; set; }
public Boolean IsGroup { get; set; } = false;
public int CompareTo(AgentTask other)
{
if (UserFunction.CompareTo(other) != 0)
{
return UserFunction.CompareTo(other);
}
else
{
return Group.CompareTo(other);
}
}
public override bool Equals(object obj)
{
var newObj = obj as AgentTask;
if (null != newObj)
{
return Equals(newObj);
}
else
{
return base.Equals(obj);
}
}
public bool Equals(AgentTask other)
{
if (null != other)
{
return this.UserFunction == other.UserFunction
//&& this.PreferredTime == newObj.PreferredTime
&& this.Group == other.Group
&& this.GetHashCode() == other.GetHashCode();
}
else
{
return base.Equals(other);
}
}
public override int GetHashCode()
{
int hash = 19;
unchecked
{ // allow "wrap around" in the int
hash = hash * 31 + this.UserFunction.GetHashCode();
//hash = hash * 31 + this.PreferredTime.GetHashCode(); // assuming integer
hash = hash * 31 + this.Group.GetHashCode();
}
return hash;
}
public override string ToString()
{
return base.ToString();
}
}
}
У меня также есть класс, содержащий коллекцию AgentTask, называемый Account. Упрощенная версия аккаунта будет выглядеть так:
public class Account : IdentityUser
{
...
public List UserFunctions { get; set; }
}
У меня также есть запрос LINQ, который я хочу вернуть массив учетных записей, чьи любые UserFunctions равны предварительно определенной задаче AgentTask . Мой запрос выглядит так:
var accounts = _context.Accounts.Include(x => x.UserFunctions)
.Where((a) => a.UserFunctions.Any((t) => t.Equals(task))).ToArray();
Проблема, с которой я столкнулся, заключается в том, что переменная account всегда имеет массив длины 0. Почему?
Моя консоль вывода выглядит так (чего я не понимаю):
SELECT "a"."Id", "a"."AcceptTerms", "a"."AccessFailedCount", "a"."ConcurrencyStamp", "a"."Created", "a"."DOB", "a"."Email", "a"."EmailConfirmed", "a"."FirstName", "a"."LastName", "a"."LockoutEnabled", "a"."LockoutEnd", "a"."NormalizedEmail", "a"."NormalizedUserName", "a"."NotifyThreeDaysBefore", "a"."NotifyWeekBefore", "a"."PasswordHash", "a"."PasswordReset", "a"."PhoneNumber", "a"."PhoneNumberConfirmed", "a"."ResetToken", "a"."ResetTokenExpires", "a"."Role", "a"."SecurityStamp", "a"."Title", "a"."TwoFactorEnabled", "a"."Updated", "a"."UserName", "a"."VerificationToken", "a"."Verified", "u0"."FunctionId", "u0"."AccountId", "u0"."Group", "u0"."IsGroup", "u0"."PreferredTime", "u0"."UserFunction"
FROM "AspNetUsers" AS "a"
LEFT JOIN "UserFunctions" AS "u0" ON "a"."Id" = "u0"."AccountId"
WHERE EXISTS (
SELECT 1
FROM "UserFunctions" AS "u"
WHERE "a"."Id" = "u"."AccountId" AND "u"."FunctionId" = @__entity_equality_task_0_FunctionId)
ORDER BY "a"."Id"
Подробнее здесь: https://stackoverflow.com/questions/787 ... expression
Метод Equals никогда не вызывается выражением LINQ ⇐ C#
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
PYSAT Как применить Clausify к объекту Equals при использовании объекта Equals в CNF?
Anonymous » » в форуме Python - 0 Ответы
- 45 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Ошибка матча по каратэ: совпадение не удалось: EQUALS $ | совпадение не удалось: EQUALS
Anonymous » » в форуме JAVA - 0 Ответы
- 45 Просмотры
-
Последнее сообщение Anonymous
-