Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Problem Complex Model

$
0
0

Already this week, I understand. Nothing happens. Configure authentication, it is impossible to make a comprehensive model.External Key (ForeignKey) added MySQL and the class is not initialized.
What is the problem?

[ComplexType]    public class ApplicationUser: IdentityUser {        public float Money {get; set; }        public string FinanceId {get; set; }        public virtual FinanceOperation Finance {get; set; }    }



FinanceId is, I've tested.But FinanceOperation not initialized.

[Table ( "financeoperations")]    public class FinanceOperation {        public string Id {get; set; }        public float Operation {get; set; }    }



Trying to appeal to this class:
this Controller: ManageController // Identity

[HttpGet]        public async Task <string> Index () {            string id = GetCurrentIdUser ();           // ApplicationUser user = _context.Users.FirstOrDefault (p => p.Id == id); // The user is, but Finance is not initialized.           . // ApplicationUser user = await _userManager.GetCureentUserAsync () Result; // The user is, but is not initialized Finance            if (user == null) return "User Error";            return user.Finance.Id.ToString (); // Here mistake that Finance is not initialized.        }



DbContext:

public class ApplicationDbContext: IdentityDbContext <ApplicationUser> {        public ApplicationDbContext (DbContextOptions <ApplicationDbContext> options): base (options) {}        protected override void OnModelCreating (ModelBuilder builder) {            base.OnModelCreating (builder);        }    }



As I have already tried everything?


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>