The type of entity framework; it is not part of the model for the current context. when you load the excel file from the aspx page

I have a page .aspx where I want to upload an Excel file and insert the data from the excel file into the database.

I had no idea about this practice, so I googled and found a tutorial on how to do it. So he created a separate project, following the same instructions given in the tutorial and they were done. So implemented the same things in my actual project.

  • Connect Excel using Entity Framework
  • C # Converting decimals from 0 to string adds a thousand seperators and a lot of 0s
  • EFCodeFirst 4.2 Manifesto Tokens and Provider
  • Import and export of Excel to SQL
  • Excel is unable to connect to the SQL Server database after calling a C # COM DLL

To run my business, I am using EntityFramework . Now everything is set in place of him, but when I am running my project and uploaded excel file and hitting the submit button, he is giving me error. The entity type tblUserDetails is not part of the model for the current context.

Here is my code:

// Import to Database using (pwpEntities dc = new pwpEntities()) { foreach (DataRow dr in ds.Tables[0].Rows) { string FirstName = dr[“First Name”].ToString(); var v = dc.tblUserDetailsProp.Where(a => a.vchFirstName.Equals(FirstName)).FirstOrDefault(); if (v != null) { // Update here v.CompanyName = dr[“Company Name”].ToString(); v.vchLocation = dr[“Location”].ToString(); v.vchFirstName = dr[“First Name”].ToString(); v.vchMobile1 = dr[“Mobile 1”].ToString(); v.vchMobile = dr[“Mobile”].ToString(); v.vchEmail = dr[“Email”].ToString(); v.vchUserName = dr[“User Name”].ToString(); v.ServiceId = Convert.ToInt32(dr[“Service Id”]); v.vchPassword = dr[“Password”].ToString(); v.UserTypeFkId = Convert.ToInt32(dr[“UserTypeFkId”]); } else { // Insert dc.tblUserDetailsProp.Add(new tblUserDetails { CompanyName = dr[“Company Name”].ToString(), vchLocation = dr[“Location”].ToString(), vchFirstName = dr[“First Name”].ToString(), vchMobile1 = dr[“Mobile 1”].ToString(), vchMobile = dr[“Mobile”].ToString(), vchEmail = dr[“Email”].ToString(), vchUserName = dr[“User Name”].ToString(), ServiceId = Convert.ToInt32(dr[“Service Id”]), vchPassword = dr[“Password”].ToString(), UserTypeFkId = Convert.ToInt32(dr[“UserTypeFkId”]) }); } } dc.SaveChanges(); }

It is the exception to throw here var v = dc.tblUserDetailsProp.Where(a => a.vchFirstName.Equals(FirstName)).FirstOrDefault(); .

  • Advice on how to store the data type – List , dictionary, XML, lines or?
  • in a .net application Microsoft.Office.Interop.Excel.Workbooks.Open () works only in debug mode
  • View nested records on wpf UI
  • Best way to insert rows in relational tables
  • Entity framework ;, dll, excel
Review: Tower of Time
READ

Other pages of pages: MyModel.cs: –

public partial class tblUserDetails { public int intId { get; set; } public string vchFirstName { get; set; } public string vchLastName { get; set; } public string vchUserName { get; set; } public string vchPassword { get; set; } public string vchEmail { get; set; } public string vchIMEI { get; set; } public Nullable<double> Weight { get; set; } … }

MyModel.Context.cs: –

using System; using System.Data.Entity; using System.Data.Entity.Infrastructure; public partial class pwpEntities : DbContext { public pwpEntities() : base(“name=pwpEntities”) { } protected override void OnModelCreating(DbModelBuilder modelBuilder) { throw new UnintentionalCodeFirstException(); } public DbSet<tblUserDetails> tblUserDetailsProp { get; set; } }

Please help me, I wasted my hours by eliminating this error. I have visited all the sites on the internet, but have not found a solution.

If this error occurs on your project, it may be for a few reasons. Double check and make sure the entity framework maps; are correct. Continue Please see this post.