Deprecated: Creation of dynamic property Kirki_Toolkit::$modules is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/kirki.php on line 67

Deprecated: Creation of dynamic property Kirki_Field_Switch::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Textarea::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Switch::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Checkbox::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Toggle::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Radio::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Checkbox::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Custom::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Custom::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Switch::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Radio_Image::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Radio::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Multicheck::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Switch::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Number::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Checkbox::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Switch::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Text::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Radio_Image::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Multicheck::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Switch::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Checkbox::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Checkbox::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Switch::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Switch::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Switch::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Switch::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Radio_Image::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Custom::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Deprecated: Creation of dynamic property Kirki_Field_Custom::$label is deprecated in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php on line 291

Warning: Cannot modify header information - headers already sent by (output started at /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-content/themes/hitmag/inc/kirki/core/class-kirki-field.php:291) in /home/rh00k03md44z/public_html/new.octopuscodes.com/wp-includes/feed-rss2.php on line 8
having in entity framework core Archives - OctopusCodes https://octopuscodes.com/tag/having-in-entity-framework-core/ Sun, 30 Apr 2023 05:07:59 +0000 en-US hourly 1 https://wordpress.org/?v=6.9 https://octopuscodes.com/wp-content/uploads/2022/12/cropped-logo-80x80-1-32x32.png having in entity framework core Archives - OctopusCodes https://octopuscodes.com/tag/having-in-entity-framework-core/ 32 32 Having in LINQ Query in Entity Framework Core https://octopuscodes.com/net-core-tutorial/entity-framework-core-tutorial/having-in-linq-query-in-entity-framework-core/ Sun, 30 Apr 2023 05:01:38 +0000 https://octopuscodes.com/?p=2125 Having is used to specify an additional filtering condition on the result of a grouping data from a database using Entity Framework Core. using EntityFrameworkCore_ConsoleApp.Models; namespace EntityFrameworkCore_ConsoleApp { public class …

The post Having in LINQ Query in Entity Framework Core appeared first on OctopusCodes.

]]>
Having is used to specify an additional filtering condition on the result of a grouping data from a database using Entity Framework Core.

using EntityFrameworkCore_ConsoleApp.Models;

namespace EntityFrameworkCore_ConsoleApp
{
    public class Program
    {
        static void Main(string[] args)
        {
            using (var databaseContext = new DatabaseContext())
            {
                var groups = (from product in databaseContext.Products  
                              group product by product.CategoryId into gr
                              select new
                              {
                                  gr.Key,
                                  CountProduct = gr.Count(),
                                  SumQuantities = gr.Sum(productOfGroup => productOfGroup.Price),
                                  MinPrice = gr.Min(productOfGroup => productOfGroup.Price),
                                  MaxPrice = gr.Max(productOfGroup => productOfGroup.Price),
                                  AvgPrice = gr.Average(productOfGroup => productOfGroup.Price)
                              }).Where(group => group.SumQuantities > 41).ToList();
                groups.ForEach(group =>
                {
                    Console.WriteLine("Category Id: " + group.Key);
                    Console.WriteLine("Count Product: " + group.CountProduct);
                    Console.WriteLine("Sum Quantities: " + group.SumQuantities);
                    Console.WriteLine("Min Price: " + group.MinPrice);
                    Console.WriteLine("Max Price: " + group.MaxPrice);
                    Console.WriteLine("Avg Price: " + group.AvgPrice);
                    Console.WriteLine("---------------------");
                });
            }
        }
    }
}
Category Id: 3
Count Product: 3
Sum Quantities: 79
Min Price: 17
Max Price: 43
Avg Price: 26.333333333333332
---------------------

You can use combination of Having and Skip as below:

using EntityFrameworkCore_ConsoleApp.Models;

namespace EntityFrameworkCore_ConsoleApp
{
    public class Program
    {
        static void Main(string[] args)
        {
            using (var databaseContext = new DatabaseContext())
            {
                var groups = (from product in databaseContext.Products  
                              group product by product.CategoryId into gr
                              select new
                              {
                                  gr.Key,
                                  CountProduct = gr.Count(),
                                  SumQuantities = gr.Sum(productOfGroup => productOfGroup.Price),
                                  MinPrice = gr.Min(productOfGroup => productOfGroup.Price),
                                  MaxPrice = gr.Max(productOfGroup => productOfGroup.Price),
                                  AvgPrice = gr.Average(productOfGroup => productOfGroup.Price)
                              }).Where(group => group.SumQuantities > 41).Skip(1).ToList();
                groups.ForEach(group =>
                {
                    Console.WriteLine("Category Id: " + group.Key);
                    Console.WriteLine("Count Product: " + group.CountProduct);
                    Console.WriteLine("Sum Quantities: " + group.SumQuantities);
                    Console.WriteLine("Min Price: " + group.MinPrice);
                    Console.WriteLine("Max Price: " + group.MaxPrice);
                    Console.WriteLine("Avg Price: " + group.AvgPrice);
                    Console.WriteLine("---------------------");
                });
            }
        }
    }
}
Category Id: 3
Count Product: 3
Sum Quantities: 63
Min Price: 17
Max Price: 43
Avg Price: 26.333333333333332
---------------------

You can use combination of Having and Skip and Take as below:

using EntityFrameworkCore_ConsoleApp.Models;

namespace EntityFrameworkCore_ConsoleApp
{
    public class Program
    {
        static void Main(string[] args)
        {
            using (var databaseContext = new DatabaseContext())
            {
                var groups = (from product in databaseContext.Products  
                              group product by product.CategoryId into gr
                              select new
                              {
                                  gr.Key,
                                  CountProduct = gr.Count(),
                                  SumQuantities = gr.Sum(productOfGroup => productOfGroup.Price),
                                  MinPrice = gr.Min(productOfGroup => productOfGroup.Price),
                                  MaxPrice = gr.Max(productOfGroup => productOfGroup.Price),
                                  AvgPrice = gr.Average(productOfGroup => productOfGroup.Price)
                              }).Where(group => group.SumQuantities > 41).Skip(0).Take(2).ToList();
                groups.ForEach(group =>
                {
                    Console.WriteLine("Category Id: " + group.Key);
                    Console.WriteLine("Count Product: " + group.CountProduct);
                    Console.WriteLine("Sum Quantities: " + group.SumQuantities);
                    Console.WriteLine("Min Price: " + group.MinPrice);
                    Console.WriteLine("Max Price: " + group.MaxPrice);
                    Console.WriteLine("Avg Price: " + group.AvgPrice);
                    Console.WriteLine("---------------------");
                });
            }
        }
    }
}
Category Id: 3
Count Product: 3
Sum Quantities: 79
Min Price: 17
Max Price: 43
Avg Price: 26.333333333333332
---------------------

You can use combination of Having and Skip and Take and OrderBy as below:

using EntityFrameworkCore_ConsoleApp.Models;

namespace EntityFrameworkCore_ConsoleApp
{
    public class Program
    {
        static void Main(string[] args)
        {
            using (var databaseContext = new DatabaseContext())
            {
                var groups = (from product in databaseContext.Products  
                              group product by product.CategoryId into gr
                              select new
                              {
                                  gr.Key,
                                  CountProduct = gr.Count(),
                                  SumQuantities = gr.Sum(productOfGroup => productOfGroup.Price),
                                  MinPrice = gr.Min(productOfGroup => productOfGroup.Price),
                                  MaxPrice = gr.Max(productOfGroup => productOfGroup.Price),
                                  AvgPrice = gr.Average(productOfGroup => productOfGroup.Price)
                              }).Where(group => group.SumQuantities > 41).Skip(0).Take(2).OrderByDescending(group => group.SumQuantities).ToList();
                groups.ForEach(group =>
                {
                    Console.WriteLine("Category Id: " + group.Key);
                    Console.WriteLine("Count Product: " + group.CountProduct);
                    Console.WriteLine("Sum Quantities: " + group.SumQuantities);
                    Console.WriteLine("Min Price: " + group.MinPrice);
                    Console.WriteLine("Max Price: " + group.MaxPrice);
                    Console.WriteLine("Avg Price: " + group.AvgPrice);
                    Console.WriteLine("---------------------");
                });
            }
        }
    }
}
Category Id: 3
Count Product: 3
Sum Quantities: 79
Min Price: 17
Max Price: 43
Avg Price: 26.333333333333332
---------------------

The post Having in LINQ Query in Entity Framework Core appeared first on OctopusCodes.

]]>
Having in LINQ MeThods in Entity Framework Core https://octopuscodes.com/net-core-tutorial/entity-framework-core-tutorial/having-in-linq-methods-in-entity-framework-core/ Sat, 15 Apr 2023 02:40:18 +0000 https://octopuscodes.com/?p=1767 Having is used to specify an additional filtering condition on the result of a grouping data from a database using Entity Framework Core. using EntityFrameworkCore_ConsoleApp.Models; namespace EntityFrameworkCore_ConsoleApp { public class …

The post Having in LINQ MeThods in Entity Framework Core appeared first on OctopusCodes.

]]>
Having is used to specify an additional filtering condition on the result of a grouping data from a database using Entity Framework Core.

using EntityFrameworkCore_ConsoleApp.Models;

namespace EntityFrameworkCore_ConsoleApp
{
    public class Program
    {
        static void Main(string[] args)
        {
            using (var databaseContext = new DatabaseContext())
            {
                var groups = databaseContext.Products.GroupBy(product => product.CategoryId).Select(group => new
                {
                    group.Key,
                    CountProduct = group.Count(),
                    SumQuantities = group.Sum(productOfGroup => productOfGroup.Quantity),
                    MinPrice = group.Min(productOfGroup => productOfGroup.Price),
                    MaxPrice = group.Max(productOfGroup => productOfGroup.Price),
                    AvgPrice = group.Average(productOfGroup => productOfGroup.Price)
                }).Where(group => group.SumQuantities > 41).ToList();
                groups.ForEach(group =>
                {
                    Console.WriteLine("Category Id: " + group.Key);
                    Console.WriteLine("Count Product: " + group.CountProduct);
                    Console.WriteLine("Sum Quantities: " + group.SumQuantities);
                    Console.WriteLine("Min Price: " + group.MinPrice);
                    Console.WriteLine("Max Price: " + group.MaxPrice);
                    Console.WriteLine("Avg Price: " + group.AvgPrice);
                    Console.WriteLine("---------------------");
                });
            }
        }
    }
}
Category Id: 2
Count Product: 2
Sum Quantities: 42
Min Price: 4
Max Price: 15
Avg Price: 9.5
---------------------
Category Id: 3
Count Product: 3
Sum Quantities: 63
Min Price: 17
Max Price: 43
Avg Price: 26.333333333333332
---------------------

You can use combination of Having and Skip method as below:

using EntityFrameworkCore_ConsoleApp.Models;

namespace EntityFrameworkCore_ConsoleApp
{
    public class Program
    {
        static void Main(string[] args)
        {
            using (var databaseContext = new DatabaseContext())
            {
                var groups = databaseContext.Products.GroupBy(product => product.CategoryId).Select(group => new
                {
                    group.Key,
                    CountProduct = group.Count(),
                    SumQuantities = group.Sum(productOfGroup => productOfGroup.Quantity),
                    MinPrice = group.Min(productOfGroup => productOfGroup.Price),
                    MaxPrice = group.Max(productOfGroup => productOfGroup.Price),
                    AvgPrice = group.Average(productOfGroup => productOfGroup.Price)
                }).Where(group => group.SumQuantities > 41).Skip(1).ToList();
                groups.ForEach(group =>
                {
                    Console.WriteLine("Category Id: " + group.Key);
                    Console.WriteLine("Count Product: " + group.CountProduct);
                    Console.WriteLine("Sum Quantities: " + group.SumQuantities);
                    Console.WriteLine("Min Price: " + group.MinPrice);
                    Console.WriteLine("Max Price: " + group.MaxPrice);
                    Console.WriteLine("Avg Price: " + group.AvgPrice);
                    Console.WriteLine("---------------------");
                });
            }
        }
    }
}
Category Id: 3
Count Product: 3
Sum Quantities: 63
Min Price: 17
Max Price: 43
Avg Price: 26.333333333333332
---------------------

You can use combination of Having and Skip method and Take method as below:

using EntityFrameworkCore_ConsoleApp.Models;

namespace EntityFrameworkCore_ConsoleApp
{
    public class Program
    {
        static void Main(string[] args)
        {
            using (var databaseContext = new DatabaseContext())
            {
                var groups = databaseContext.Products.GroupBy(product => product.CategoryId).Select(group => new
                {
                    group.Key,
                    CountProduct = group.Count(),
                    SumQuantities = group.Sum(productOfGroup => productOfGroup.Quantity),
                    MinPrice = group.Min(productOfGroup => productOfGroup.Price),
                    MaxPrice = group.Max(productOfGroup => productOfGroup.Price),
                    AvgPrice = group.Average(productOfGroup => productOfGroup.Price)
                }).Where(group => group.SumQuantities > 41).Skip(0).Take(2).ToList();
                groups.ForEach(group =>
                {
                    Console.WriteLine("Category Id: " + group.Key);
                    Console.WriteLine("Count Product: " + group.CountProduct);
                    Console.WriteLine("Sum Quantities: " + group.SumQuantities);
                    Console.WriteLine("Min Price: " + group.MinPrice);
                    Console.WriteLine("Max Price: " + group.MaxPrice);
                    Console.WriteLine("Avg Price: " + group.AvgPrice);
                    Console.WriteLine("---------------------");
                });
            }
        }
    }
}
Category Id: 2
Count Product: 2
Sum Quantities: 42
Min Price: 4
Max Price: 15
Avg Price: 9.5
---------------------
Category Id: 3
Count Product: 3
Sum Quantities: 63
Min Price: 17
Max Price: 43
Avg Price: 26.333333333333332
---------------------

You can use combination of Having and Skip method and Take method and OrderBy method as below:

using EntityFrameworkCore_ConsoleApp.Models;

namespace EntityFrameworkCore_ConsoleApp
{
    public class Program
    {
        static void Main(string[] args)
        {
            using (var databaseContext = new DatabaseContext())
            {
                var groups = databaseContext.Products.GroupBy(product => product.CategoryId).Select(group => new
                {
                    group.Key,
                    CountProduct = group.Count(),
                    SumQuantities = group.Sum(productOfGroup => productOfGroup.Quantity),
                    MinPrice = group.Min(productOfGroup => productOfGroup.Price),
                    MaxPrice = group.Max(productOfGroup => productOfGroup.Price),
                    AvgPrice = group.Average(productOfGroup => productOfGroup.Price)
                }).Where(group => group.SumQuantities > 41).Skip(0).Take(2).OrderByDescending(group => group.SumQuantities).ToList();
                groups.ForEach(group =>
                {
                    Console.WriteLine("Category Id: " + group.Key);
                    Console.WriteLine("Count Product: " + group.CountProduct);
                    Console.WriteLine("Sum Quantities: " + group.SumQuantities);
                    Console.WriteLine("Min Price: " + group.MinPrice);
                    Console.WriteLine("Max Price: " + group.MaxPrice);
                    Console.WriteLine("Avg Price: " + group.AvgPrice);
                    Console.WriteLine("---------------------");
                });
            }
        }
    }
}
Category Id: 3
Count Product: 3
Sum Quantities: 63
Min Price: 17
Max Price: 43
Avg Price: 26.333333333333332
---------------------
Category Id: 2
Count Product: 2
Sum Quantities: 42
Min Price: 4
Max Price: 15
Avg Price: 9.5
---------------------

The post Having in LINQ MeThods in Entity Framework Core appeared first on OctopusCodes.

]]>