سلام
دو تاکلاس زیر را داریم
namespace WebApplication2.Models { public class User { public User() { } public int ID { get; set; } public string username { get; set; } public string Password { get; set; } public virtual Status Status { get; set; } public int StatusId { get; set; } } } using System.Collections.Generic; namespace WebApplication2.Models { public class Status { public Status() { } public int Id { get; set; } public string Name { get; set; } public virtual List<User> Users { get; set; } } }
ویک کلاس دیگر داریم
namespace WebApplication2.Models { public class UserProfile { public int ID { get; set; } public string Username { get; set; } public string Password { get; set; } public int StatusId { get; set; } public string StatusName { get; set; } } }
و یک کلاس Repositories تعریف ایجاد کرده ایم
using System; using System.Collections.Generic; using System.Linq; namespace WebApplication2.Models { public class UserRepositories { private Context _db; public UserRepositories() { _db = new Context(); } public Array ListUser() { return _db.Users .Join(_db.Statuses, u => u.StatusId, s => s.Id, (u, s) => new { u, s }) .Select(current => new { userId = current.u.ID, userName = current.u.username, password = current.u.Password, statusId = current.u.StatusId, statusName=current.s.Name }).ToArray(); } public IEnumerable<UserProfile> List() { try { var a = _db.Users .Join(_db.Statuses, u => u.StatusId, s => s.Id, (u, s) => new { u, s }) .Select(current => new { ID = current.u.ID, Username = current.u.username, Password = current.u.Password, StatusId = current.u.StatusId, StatusName = current.s.Name }); return a.ToList(); } catch { return null; } } } }
که تابع
public IEnumerable<UserProfile> List()
ارور دارد برای رفع این مشکل باید چگونه کد را تغییر بدهم
Cannot implicitly convert type 'System.Collections.Generic.List<<anonymous type: int ID, string Username, string Password, int StatusId, string StatusName>>' to 'System.Collections.Generic.IEnumerable<WebApplication2.Models.UserProfile>'. An explicit conversion exists (are you missing a cast?)
باتشکر
این پست در تاریخ {{ dateString(new Date(post.deleteDate)) }} توسط {{ post.deletedByUser }} حذف شده است.
دلیل حذف: {{ post.deleteReason ?? 'نامشخص' }}
زمان پاسخ گویی روز های شنبه الی چهارشنبه ساعت 9 الی 18
فقط به موضوعات مربوط به محصولات آموزشی و فروش پاسخ داده می شود