title: How can I connect IdentityUser with Recipe in ASP.NET MVC
body: <p>I want to create One-To-Many relationship in ASP.NET.CORE MVC, between IdentityUser and Recipe. When i try to assign ApplicationUserId to curently logged in userId it gets null value. When i open AspNetUsers in server explorer it doens't have Recipes property. I dont't  know how to get it to work properly</p>
  <p><strong>ApplicationUser.cs</strong></p>
  <pre><code> namespace WebApplication.Models
      {
          public class ApplicationUser : IdentityUser
          {
             
            public List&lt;Recipe&gt; Recipes { get; set; }
          }
      }
  </code></pre>
  <p><strong>RecipeController.cs</strong></p>
  <pre><code>    namespace WebApplication.Controllers
      {
          public class RecipeController : Controller
          {
              private readonly ApplicationDbContext _applicationDbContext;
              private readonly UserManager&lt;ApplicationUser&gt; _userManager;
              private readonly SignInManager&lt;ApplicationUser&gt; _signInManager;
              public RecipeController( ApplicationDbContext applicationDbContext, UserManager&lt;ApplicationUser&gt; userManager, SignInManager&lt;ApplicationUser&gt; signInManager)
              {
                  _signInManager = signInManager;
                  _applicationDbContext = applicationDbContext;
                  _userManager = userManager;
              }
      
              public IActionResult Create()
              {
      
                  var userId = _userManager.GetUserId(User);
                  return View();
              }
              [HttpPost]
              public async Task&lt;IActionResult&gt; Create([Bind(&quot;RecipeName,RecipeContent&quot;)] Recipe recipe)
              {
                  var userId = _userManager.GetUserId(User);
                      recipe.ApplicationUserId = userId;
                      _applicationDbContext.Recipes.Add(recipe);
                      await _applicationDbContext.SaveChangesAsync();
                      return View(recipe);
  
  
          }
       
      }
  }
  </code></pre>
  <p><strong>Recipe.cs</strong></p>
  <pre><code>namespace WebApplication.Models
  {
      public class Recipe
      {
          [Key]
          public Guid Id { get; set; }
          [Required]
          public string RecipeName { get; set; }
          [Required]
          public string RecipeContent { get; set; }
          public string ApplicationUserId { get; set; }
          public ApplicationUser ApplicationUser { get; set; }
      }
  }
  </code></pre>
  <p><strong>Startup.cs</strong></p>
  <pre><code>namespace WebApplication
  {
      public class Startup
      {
          public Startup(IConfiguration configuration)
          {
              Configuration = configuration;
          }
  
          public IConfiguration Configuration { get; }
  
          // This method gets called by the runtime. Use this method to add services to the container.
          public void ConfigureServices(IServiceCollection services)
          {
              services.AddControllersWithViews();
              services.AddDbContext&lt;ApplicationDbContext&gt;(option =&gt; option.UseSqlServer(Configuration.GetConnectionString(&quot;DefaultConnection&quot;)));
              services.AddIdentity&lt;ApplicationUser, IdentityRole&gt;().AddEntityFrameworkStores&lt;ApplicationDbContext&gt;();
  
          }
  
          // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
          public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
          {
              if (env.IsDevelopment())
              {
                  app.UseDeveloperExceptionPage();
              }
              else
              {
                  app.UseExceptionHandler(&quot;/Home/Error&quot;);
                  // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                  app.UseHsts();
              }
              app.UseHttpsRedirection();
              app.UseStaticFiles();
  
              app.UseRouting();
              app.UseAuthentication();
              app.UseAuthorization();
  
              app.UseEndpoints(endpoints =&gt;
              {
                  endpoints.MapControllerRoute(
                      name: &quot;default&quot;,
                      pattern: &quot;{controller=Home}/{action=Index}/{id?}&quot;);
              });
          }
      }
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/pnzn0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pnzn0.png" alt="Database schema" /></a></p>