Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Sum, Count and Average on lambda on view

$
0
0

Since EF Core has no Scaffolding for Views how do i solve this?

using System;
using System.Collections.Generic;

namespace Design.Models
{
    public partial class Categories
    {
        public Categories()
        {
            Submissions = new HashSet<Submissions>();
        }

        public int IdCategorie { get; set; }
        public string Categorie { get; set; }

        public ICollection<Submissions> Submissions { get; set; }
    }
}

-------------------------------------------------------------------------------------------------

using System;
using System.Collections.Generic;

namespace Design.Models
{
    public partial class Ratings
    {
        public int IdRating { get; set; }
        public int? IdSubmission { get; set; }
        public int? Rate { get; set; }
        public string Session { get; set; }

        public Submissions RateNavigation { get; set; }
    }
}

--------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace Design.Models
{
    public partial class Submissions
    {
        public Submissions()
        {
            Ratings = new HashSet<Ratings>();
        }

        public int IdSubmission { get; set; }
        public string IdArtist { get; set; }
        public int? Categorie { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
        public float? Rating { get; set; }
        public string Source { get; set; }
       
        [DataType(DataType.Date)]
        public DateTime? Date { get; set; }

        public Categories CategorieNavigation { get; set; }
        public ICollection<Ratings> Ratings { get; set; }
    }
}

-----------------------------------------------------------------------------------------
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using Design.Models;

namespace Design.Models
{
    public partial class designContext : DbContext
    {
        public virtual DbSet<Categories> Categories { get; set; }
        public virtual DbSet<Ratings> Ratings { get; set; }
        public virtual DbSet<Submissions> Submissions { get; set; }


        public designContext(DbContextOptions<designContext> options)
    : base(options)
{ }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Categories>(entity =>
            {
                entity.HasKey(e => e.IdCategorie);

                entity.Property(e => e.IdCategorie).HasColumnName("ID_Categorie");

                entity.Property(e => e.Categorie).HasMaxLength(50);
            });

            modelBuilder.Entity<Ratings>(entity =>
            {
                entity.HasKey(e => e.IdRating);

                entity.Property(e => e.IdRating).HasColumnName("ID_Rating");

                entity.Property(e => e.IdSubmission).HasColumnName("ID_Submission");

                entity.Property(e => e.Session).HasMaxLength(36);

                entity.HasOne(d => d.RateNavigation)
                    .WithMany(p => p.Ratings)
                    .HasForeignKey(d => d.Rate)
                    .HasConstraintName("FK_Ratings_Submissions1");
            });

            modelBuilder.Entity<Submissions>(entity =>
            {
                entity.HasKey(e => e.IdSubmission);

                entity.Property(e => e.IdSubmission).HasColumnName("ID_Submission");

                entity.Property(e => e.Date).HasColumnType("date");

                entity.Property(e => e.Description).HasColumnType("text");

                entity.Property(e => e.IdArtist)
                    .HasColumnName("ID_Artist")
                    .HasMaxLength(50);

                entity.Property(e => e.Name).HasMaxLength(50);

                entity.Property(e => e.Source).HasMaxLength(50);

                entity.HasOne(d => d.CategorieNavigation)
                    .WithMany(p => p.Submissions)
                    .HasForeignKey(d => d.Categorie)
                    .HasConstraintName("FK_Submissions_Categories");
            });
        }

        public DbSet<Design.Models.ApplicationUser> ApplicationUser { get; set; }
    }
}

How can i create an Index to summarize that for each IdArtist have Count Number of Submissions,Sum of Rating and Average of Rate?


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>