Base solution for your next web application
Open Closed

multi level table #1894


User avatar
0
avanekar02 created

hello

i have the following table structure

  1. Course |________CourseDetails |_____________________Educators

earlier i created a service to get course with coursedetails works fine but when i added the Educators as a collection in coursedetails the program stops saying internal server error

my

function

in the interface ListResultDto<CourseListDto1> GetCourse(GetCoursesInput input);

in the service inheriting the interface public ListResultDto<CourseListDto> GetCourseNoEdu(GetCoursesInput input) { var courses = _courseRepository .GetAll() .Where(p => p.Type == CourseType.Live) .Include(p => p.CourseDetails) .WhereIf( !input.Filter.IsNullOrEmpty(), p => p.Name.Contains(input.Filter) ) .OrderBy(p => p.Name) .ToList();

        return new ListResultDto&lt;CourseListDto&gt;(courses.MapTo&lt;List&lt;CourseListDto&gt;>());
    }

my dto for course

[AutoMapFrom(typeof(Course))] public class CourseListDto1 : FullAuditedEntityDto {

    public string Name { get; set; }
    public string CourseDesc { get; set; }
    public string ARName { get; set; }
    public string ARCourseDesc { get; set; }

    public virtual ICollection&lt;CourseDetailListDto&gt; CourseDetails { get; set; }
}

My DTO for CourseDetail

public class CourseDetailListDto : FullAuditedEntityDto { public int CourseId { get; set; } public string Title { get; set; } public string CourseDesc { get; set; } public string CourseDetDesc { get; set; } public string Requirement { get; set; } public string Image { get; set; } public string ARTitle { get; set; } public string ARCourseDesc { get; set; } public DateTime StartDate { get; set; } public int Duration { get; set; } public string DurationUnit { get; set; } public int HrWeek { get; set; } public decimal Price { get; set; } public int CountReg { get; set; } public string CourseUrl { get; set; }

    public virtual Educator educator { get; set; }

}

and my call in index.js

vm.courses = [];

function getCourse() {
            courseService.getCourse({}).success(function (result) {
                vm.courses = result.items;
            })
        
            ;
        }

gives internal server error data

if i comment the public virtual Educator educator { get; set; } in the coursedetails it work fine , if i uncomment it fails

please tell me how to define vm.course in index to recieve multi level


3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    You shouldn't use entities in your DTOs. Define a dto class for Educator and use it instead of

    public virtual Educator educator { get; set; }
    

    in CourseDetailListDto.

  • User Avatar
    0
    avanekar02 created

    i changed the statement

    public virtual Educator educator { get; set; }

    to

    public virtual EducatorListDto educator { get; set; }

    replacing the entity with a

    [AutoMapFrom(typeof(Educator))] public class EducatorListDto : FullAuditedEntityDto { public virtual string Salute { get; set; } public virtual string Name { get; set; } public virtual string Qualification { get; set; } public virtual int Experience { get; set; } public virtual string ARName { get; set; } public virtual string ARQualification { get; set; } public virtual string Image { get; set; } public virtual int Ratings { get; set; } }

    i get the folowing error

    An exception of type 'AutoMapper.AutoMapperMappingException' occurred in Abp.dll but was not handled in user code


    can you please tell me how to address this brother

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    There must be a more detailed error message in Logs.txt file under your web project. Can you send it ?