Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从post ASP.NET CORE MVC中检索用户信息_C#_Entity Framework_Asp.net Core - Fatal编程技术网

C# 如何从post ASP.NET CORE MVC中检索用户信息

C# 如何从post ASP.NET CORE MVC中检索用户信息,c#,entity-framework,asp.net-core,C#,Entity Framework,Asp.net Core,我正在使用ASP.NET.CORE 5.0 MVC开发帮助台应用程序,现在我想从ticket中检索用户信息,如用户名、姓氏、电子邮件等 到目前为止,我创建了一个使用SQL查询的小指南 SELECT u.Id as UserId, u.UserName as Username, u.Email as UserEmail, t.UserId as TicetUserId FROM AspNetUsers u,Tickets t WHER

我正在使用ASP.NET.CORE 5.0 MVC开发帮助台应用程序,现在我想从ticket中检索用户信息,如
用户名、姓氏、电子邮件等
到目前为止,我创建了一个使用SQL查询的小指南

 SELECT u.Id as UserId,
         u.UserName as Username,
         u.Email as UserEmail,
         t.UserId as TicetUserId
  FROM AspNetUsers u,Tickets t
  WHERE u.Id = 2 and t.UserId = 2
到目前为止,我想使用
LINQ
\u unitOfWork
用C语言编写这篇文章。 我将尝试从基本模型开始演示我的模型,即
Ticket.cs

public class Ticket
    {
        [Key]
        public int Id { get; set; }

        [Display(Name = "Opis")]
        public string Description { get; set; }

        [Display(Name = "Kratak Opis")]
        [MaxLength(20, ErrorMessage = "Maximalan broj karaktera je 20")]
        public string ShortDescription { get; set; }

        [Display(Name = "Datum i vrijeme slanja")]
        public string DateAndTime { get; set; } = DateTime.Now.ToString("dd/MM/yyyy HH:mm");

        //[Display(Name = "Datum i vrijeme zavrsetka")]
        //public DateTime Answered { get; set; }

        [Display(Name = "Vrsta tiketa")]
        public int TicketTypeID { get; set; }

        [ForeignKey("TicketTypeID")]
        public virtual TicketType TicketType { get; set; }

        public int UserId { get; set; }

        [ForeignKey("UserId")]
        public virtual ApplicationUser ApplicationUser { get; set; }

        public int? ClientId { get; set; }
        [ForeignKey("ClientId")]
        public virtual Client Client { get; set; }

        public string Status { get; set; } = TicketStatus.Otvoren.ToString();

    }
从TicketModels中,我有了所有的ApplicationUser类和
UserId
,它是
ForeignKey
ApplicationUser

在ApplicationUser.cs中,我拥有需要检索的所有属性

public class ApplicationUser : IdentityUser<int>
    {

        [Required]
        [Display(Name = "Ime")]
        public string Name { get; set; }

        [Required]
        [Display(Name = "Adresa")]
        public string StreetAddress { get; set; }

        [Required]
        [Display(Name = "Grad")]
        public string City { get; set; }

        [Required]
        [Display(Name = "Postanski broj")]
        public string PostalCode { get; set; }

        public int? ClientId { get; set; }
        [ForeignKey("ClientId")]
        public Client Client { get; set; }

        [NotMapped]
        public string Role { get; set; }

        //[NotMapped]
        //public int RoleId { get; set; }

        [NotMapped]
        public IEnumerable<SelectListItem> RoleList { get; set; }

        [NotMapped]
        public IEnumerable<SelectListItem> ClientList { get; set; }
    }

这将检索正确的
TicetId
。但是如何基于UserId获取TicetId呢?

在您的
应用程序用户
模型中,您似乎没有
UserId
…是的,我有。我只是从IdentityUserAs继承,因为您的票证具有
UserId
,您可以使用
var userEmail=\u unitOfwork.Ticket.GetAll(t=>t.UserId==UserId)是的,我可以获取用户ID,但是如何获取其他用户信息,如
电子邮件
 var userEmail = _unitOfwork.Ticket.GetAll(t => t.Id == ticketId);