title: How to retrieve primary key related value in asp.net mvc
body: <p>I was researched every where that primary keys , candidate keys and foreign keys. I learnt each and every keys on asp.net MVC 5 entity framework.</p>
  
  <p>Then I generated my code using MVC automatic generated option on Visual studio and I was surrounded with Migrations with editing some features..But, here is the thing...</p>
  
  <p>I was created another model called Auction, in order to bid an item. After that, I was initialized a product ID  and other details in my Auction model. Even after that, I was try to assign user ID "using Microsoft.AspNet.Identity;"
  and its worked. The thing is I want to make a relationship between Automatic generated User's Model called "IdentityModels" and "AccountViewModels". But its not worked.</p>
  
  <pre><code>// Here is my Auction model class' segment that I took on my Auction model
  
  
  [Key]
   [Required]
   public long Id { get; internal set; }
  ........
  //other codes are avoided
  ......
  [Required]
  public string SellerUserID { get; set; }
  </code></pre>
  
  <p>Here is my AuctionController</p>
  
  <pre><code> public ActionResult ViewMyBids()
          {
              var db = new AuctionsDataContext();
              var pKey = User.Identity.GetUserId();
  
              // I want to pass the primary key in to the auction model and get the results to a list 
              var result = db.Auctions.Find().SellerUserID(pKey);
              ViewBag.mes = result.SellerUserID;
  
              return ViewMyBids();
  
          }
  </code></pre>
  
  <p>Even I don't know how to get the primary key's value
  Let's say as an example:
  there is
  Employee and Department....
  Employee has an ID,
  Employee has EmpName,
  Department has a DepartmentName,</p>
  
  <p>Department wants to know a particular employee's name...
  DO that so,</p>
  
  <p>Department table needs a foreign key  which is related to employee ID,
  within that employeeID ,it can directly assign to employee's Name which is stored in Employee table...</p>
  
  <p>So, as like that I want to assign automatic generated user ID and using that ID I need to retrieve all the data that ID has....</p>
  
  <p>How to do this, I know to use of foreign keys or composition keys .. But in my research I am unable to find any solution for this.</p>
  
  <p>So help me to solve this..Thanks.......
  pls...</p>