Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC

Activities of "carelearning"

@ismcagdas

I pasted the code you provided and I still get the error. Please see attached screenshot for details. Also included is a 7-Zip compressed version of the Logs.txt file. Logs.7z

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();

The results are attached

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;
        }
    }
  • Join the UserOrganizationUnits and OrganizationUnits as the variable "first."
  • Join UserOrganizationUnit and our custom table of "departments" in the variable called "second".
  • Join "first" and "second" as the variable called "third"
  • Return expected result as a dictionary as the variable called "result" If any of these joins use .ToList (really hitting the database) then it throws :

The specified cast from a materialized 'System.Data.Entity.Core.Objects.MaterializedDataRecord' type to the '<>f__AnonymousType142[<>f__AnonymousType122[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&lt;Dictionary&lt;long, string&gt;> GetFirstCustomKeysByUserIdAsync(IReadOnlyList&lt;long&gt; 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?

Regards,

We found an answer here: [https://forum.aspnetboilerplate.com/viewtopic.php?f=2&t=2947&p=7317&hilit=disable+ValidationConfiguration+Configuration.Validation#p7317]) We had to add

Configuration.Modules.AbpWebApi().IsValidationEnabledForControllers = false;

to disable validation on the services.

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.

Showing 41 to 50 of 108 entries