LinqPad (Works)
var results = AbpUserOrganizationUnits
.Join(Departments,
a => a.OrganizationUnitId,
d => d.OrganizationUnitId,
(p, d) => new { Projection = p, Departments = d })
.Where(x => ids.Contains(x.Projection.UserId))
.ToDictionary(x => x.Projection.UserId,
x => x.Departments.CustomKey);
C# (Errors)
var results = _userOrganizationUnitRepository
.GetAll()
.Join(_departmentRepository
.GetAll(),
a => a.OrganizationUnitId,
d => d.OrganizationUnitId,
(p, d) => new { Projection = p, Departments = d })
.Where(x => ids.Contains(x.Projection.UserId))
.ToDictionary(x => x.Projection.UserId,
x => x.Departments.CustomKey);
C# (Works)
var departments = _departmentRepository.GetAllList();
var assignments = _userOrganizationUnitRepository.GetAllList();
return departments.Join(assignments,
d => d.OrganizationUnitId,
a => a.OrganizationUnitId,
(d, a) => new { Department = d, Assignment = a })
.ToDictionary(x => x.Assignment.UserId,
x => x.Department.CustomKey);
Another point is that we can do this in Linqpad with the following code:
var ids = new List<long>{
2,
3,
4,
5,
6,
7,
8
};
var assignments = AbpUserOrganizationUnits
.Where(x => ids.Contains(x.UserId)).ToList();
var first = assignments.Join(AbpOrganizationUnits,
a => a.OrganizationUnitId,
ou => ou.Id,
(a, ou) => new { Assignments = a, OrganizationUnits = ou });
var second = AbpUserOrganizationUnits
.Join(Departments,
a => a.OrganizationUnitId,
d => d.OrganizationUnitId,
(p, d) => new { Projection = p, Departments = d });
var third = first.Join(second,
f => f.Assignments.OrganizationUnitId,
s => s.Departments.OrganizationUnitId,
(f, s) => new { First = f, Second = s });
third.Dump();
Hello,
We are trying to join AbsUsersOrganizationUnits to a custom table called "departments" as below:
public class Department : Entity, IMustHaveOrganizationUnit
{
public const int MaximumIdLength = 50;
public const int MaximumTitleLength = 50;
public string CustomKey { get; set; }
public bool Locked { get; set; } = false;
public long OrganizationUnitId { get; set; }
public virtual OrganizationUnit OrganizationUnit { get; set; }
public Department()
{
}
public Department(long organizationUnitId, string cutomKey)
{
OrganizationUnitId = organizationUnitId;
CustomKey = cutomKey;
}
}
The specified cast from a materialized 'System.Data.Entity.Core.Objects.MaterializedDataRecord' type to the '<>f__AnonymousType142[<>f__AnonymousType12
2[Abp.Authorization.Users.UserOrganizationUnit,Abp.Organizations.OrganizationUnit],<>f__AnonymousType13`2[Abp.Authorization.Users.UserOrganizationUnit,MyCompanyName.AbpZeroTemplate.Departments.Department]]' type is not valid.
The code that is failing is here:
public async Task<Dictionary<long, string>> GetFirstCustomKeysByUserIdAsync(IReadOnlyList<long> ids)
{
var assignments = _userOrganizationUnitRepository
.GetAll()
.Where(x => ids.Contains(x.UserId));
var organizationUnits = _organizationUnitRepository
.GetAll();
var departments = _departmentRepository
.GetAll();
var first = assignments
.Join(organizationUnits,
a => a.OrganizationUnitId,
ou => ou.Id,
(a, ou) => new { Assignments = a, OrganizationUnits = ou });
var second = assignments
.Join(departments,
a => a.OrganizationUnitId,
d => d.OrganizationUnitId,
(p, d) => new { Projection = p, Departments = d });
var third = first.Join(second,
f => f.Assignments.OrganizationUnitId,
s => s.Departments.OrganizationUnitId,
(f, s) => new { First = f, Second = s });
var result = await third.ToDictionaryAsync(x => x.First.Assignments.UserId,
x => x.Second.Departments.CustomKey);
return result;
}
Any suggestions would be appreciated. Thank you for your time and effort.
Dear Abp Zero Support,
On my PC and a co-workers PC we both get the following message, >angular/[email protected] requires typescript@'>=2.1.0 <2.4.0' but 2.5.2 was found instead .
I have removed typescript via
npm uninstall -g typescript
but I still get that message. This is the first Google hit [https://github.com/angular/angular/issues/19287]) and it concerns 4.4.3. I've tried a few of their suggestions unsuccessfully.
Have you encountered this issue?
Hello,
We see that we can turn validation off via an attribute here: [https://aspnetboilerplate.com/Pages/Documents/Validating-Data-Transfer-Objects#disabling-validation]) We would like to disable this globally. We are using javascript calls and MVC forms in various combination. Then we perform our own business-specific validation server-side. If a piece of data is null or undefined then it gets an error that says "....A value is required but was not present...." We want to write custom validation to catch this. Is there a way to turn this validation off globally?
@Aaron
Thank you.
The
.FirstOrDefaultAsync()
and
.GetAll()...ToListAsync()
methods are exactly what we needed.
And these changes should significantly speed up some of our methods.
Hi Aaron,
Thank you for your reply. My example was probably too simple. Your answer will indeed help in some places. A real example of our code is:
var temporaryConflicts = (await _enrollmentRepository.GetAllListAsync())
.Where(x => x is Temporary)
.Where(x => !excludedIds.Contains(x.Id))
.GroupBy(x => x.Detail.Username)
.Where(g => g.Count() > 1)
.Select(g => g.Key);
We would like something like this:
var temporaryConflicts = _enrollmentRepository.GetAllListAsync()
.WhereAsync(x => x is Temporary)
.WhereAsync(x => !excludedIds.Contains(x.Id))
.GroupByAsync(x => x.Detail.Username)
.WhereAsync(g => g.Count() > 1)
.Select(g => g.Key);
This way the filtering is done when the data is acquired (DB level) and not done afterwards (in memory).
Thanks!
Hello,
Currently we pull all information back and filter it to get single records like this:
(await _userRepository.GetAllListAysnc()).FirstOrDefault(x => x.name == "Bob");
We would like to only pull back the information we need and write something like this:
_userRepository.GetAsync(x => x.name == "Bob")
or
_userRepository.GetAsync().Where(x => x.name == "Bob")
Is this possible? We see this project doing something similar: [https://github.com/zzzprojects/LINQ-Async])
Thank you for your time.