SELECT * FROM table ORDER BY NEWID()
پاسخ:
یک مثال کامل را در این زمینه در ادامه ملاحظه میکنید:
using System; using System.Data.Entity; using System.Data.Entity.Migrations; using System.Linq; namespace Sample { public class User { public int Id { get; set; } public string Name { get; set; } public int Age { get; set; } } public class MyContext : DbContext { public DbSet<User> Users { get; set; } } public class Configuration : DbMigrationsConfiguration<MyContext> { public Configuration() { AutomaticMigrationsEnabled = true; AutomaticMigrationDataLossAllowed = true; } protected override void Seed(MyContext context) { context.Users.Add(new User { Name = "User 1", Age = 20 }); context.Users.Add(new User { Name = "User 2", Age = 25 }); context.Users.Add(new User { Name = "User 3", Age = 30 }); context.Users.Add(new User { Name = "User 4", Age = 35 }); context.Users.Add(new User { Name = "User 5", Age = 40 }); base.Seed(context); } } public static class Test { public static void RunTests() { Database.SetInitializer(new MigrateDatabaseToLatestVersion<MyContext, Configuration>()); using (var context = new MyContext()) { var randomListOfUsers = context.Users .Where(person => person.Age >= 25 && person.Age < 40) .OrderBy(person => Guid.NewGuid()) .ToList(); foreach (var person in randomListOfUsers) Console.WriteLine("{0}:{1}", person.Name, person.Age); } } } }
.OrderBy(person => Guid.NewGuid())
ORDER BY NEWID()
خروجی SQL تولیدی کوئری LINQ فوق را نیز در ادامه مشاهده میکنید:
SELECT [Project1].[Id] AS [Id], [Project1].[Name] AS [Name], [Project1].[Age] AS [Age] FROM ( SELECT NEWID() AS [C1], ------ Guid created here [Extent1].[Id] AS [Id], [Extent1].[Name] AS [Name], [Extent1].[Age] AS [Age] FROM [dbo].[Users] AS [Extent1] WHERE ([Extent1].[Age] >= 25) AND ([Extent1].[Age] < 40) ) AS [Project1] ORDER BY [Project1].[C1] ASC ------ Used for sorting here
دور کاری یا کار در محل شرکت
بررسی تغییرات و تازههای Bootstrap 4
Autofac 5.0 منتشر شد
تزریق وابستگی (DI) در ASP.NET Core
I’ve been building some ASP.NET Core apps as of late and had to dig into how Dependency Injection works there. After talking with Julie Lerman a bit on Twitter about it, I realized that there might be some confusing things about how it works in ASP.NET Core, so I’m hoping I can add some clarity in this post.
In this post, I will describe how to port a desktop application from .NET Framework to .NET Core. I picked a WinForms application as an example. Steps for WPF application are similar and I’ll describe what needs to be done different for WPF as we go. I will also show how you can keep using the WinForms designer in Visual Studio even though it is under development and is not yet available for .NET Core projects.
As part of our .NET unification, Xamarin.iOS and Xamarin.Android will become part of .NET 6 as .NET for iOS and .NET for Android. Because these bindings are projections of the SDKs shipped from Apple and Google, nothing changes there, however build tooling, target framework monikers, and runtime framework monikers will be updated to match all other .NET 6 workloads. Our commitment to keeping .NET developers up-to-date with the latest mobile SDKs is foundational to .NET MAUI and remains firm. When .NET 6 ships, we expect to ship a final release of Xamarin SDKs in their current form that will be serviced for a year. All modern work will at that time shift to .NET 6.
تفکر درباره mvc 5,mvc 6,mvc flash 3
Over five years ago I released MvcFlash, and soon after I released the second iteration MvcFlash2. Don't let the terrible naming and versioning fool you, this is one of my favorite creations. As ASP.NET 5 starts to take root and MVC 6 blossoms, I begin to feel more confident about creating the next version of MvcFlash. Honestly, I can't see developing an MVC application without it. Before I do, I thought I would muse about the possible challenges ahead.