After doing some research, I found ways to do what my question asks, however, I'm trying to do this inside a function called
GetAssignedToDDL
List<SelectListItem>
Cannot implicitly convert type
'System.Collections.Generic.List'
to
'System.Collections.Generic.List' LWC C:\Users\runningexe\Desktop\LincolnWaterCommissionWorkOrderInventorySystem\LWC\LWC\Controllers\WorkOrderController.cs 201 Active
List<SelectListItem
private static List<SelectListItem> GetAssignedToDDL()
{
List<SelectListItem> assignedToList = new List<SelectListItem>();
var dbContext = new ApplicationDbContext();
var userList = dbContext.Users.ToList();
assignedToList = userList.Select(u => new SelectListItem
{
Text = u.UserName,
Value = u.Id
}).ToList();
return assignedToList;
}
private static List<SelectListItem> GetAssignedToDDL()
{
return userManager.Users.ToList();
}
No database provider has been configured for this DbContext. A provider can be configured by overriding the DbContext.OnConfiguring method or by using AddDbContext on the application service provider. If AddDbContext is used, then also ensure that your DbContext type accepts a DbContextOptions object in its constructor and passes it to the base constructor for DbContext.
You can use LINQ's Select
function. On the line where you see the compilation error, try appending the following:
.Select(u => new SelectListItem { Text = u.UserName, Value = u.Id }).ToList();
If you include your code, I can edit this answer to make it more specific to your use case. You will also need to include using System.Linq;
if it's not already there.
If you're not familiar with Select
, it's effectively known as a mapping
function. You can find a good explanation here.