tag:blogger.com,1999:blog-6082652835152798567.post8760551957887886628..comments2024-03-28T21:41:58.974-07:00Comments on Sql server, .net and c# video tutorial: Part 8 - Data access in mvc using entity frameworkUnknownnoreply@blogger.comBlogger94125tag:blogger.com,1999:blog-6082652835152798567.post-35865961027041239632020-02-06T03:59:16.711-08:002020-02-06T03:59:16.711-08:00using System;
using System.Collections.Generic;
us...using System;<br />using System.Collections.Generic;<br />using System.ComponentModel.DataAnnotations.Schema;<br />using System.Linq;<br />using System.Web;<br /><br /><br />namespace DemoTwo.Models<br />{<br /> [Table(tblEmployee)]<br /> public class Employee<br /> {<br /> public int EmployeeId { get; set; }<br /> public string Name { get; set; }<br /> public string Gender { get; set; }<br /> public string City { get; set; }<br /> }<br />}<br /><br /><br />Severity Code Description Project File Line Suppression State<br />Error CS0103 The name 'tblEmployee' does not exist in the current context DemoTwo C:\Users\Mahesh\source\repos\DemoTwo\Models\Employee.cs 10 Active<br />Vijayhttps://www.blogger.com/profile/07915964082787853822noreply@blogger.comtag:blogger.com,1999:blog-6082652835152798567.post-21270193058002321242019-12-08T08:29:55.520-08:002019-12-08T08:29:55.520-08:00Sir, Showing Entity Framework Exception in Employe...Sir, Showing Entity Framework Exception in Employee Controller <br />The underlying provider failed on Open.<br />please tell me the solution sir<br />please look the Connection String in web.config<br />Rajhttps://www.blogger.com/profile/07906172674317773735noreply@blogger.comtag:blogger.com,1999:blog-6082652835152798567.post-6746864975178442132019-05-13T21:56:13.603-07:002019-05-13T21:56:13.603-07:00You have not added DbContext..
public class Emplo...You have not added DbContext..<br /><br />public class EmployeeContext:DbContext<br /> {<br /> public DbSet Employees { get; set; }<br /> }Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-6082652835152798567.post-53811267574293169732018-12-04T06:35:37.852-08:002018-12-04T06:35:37.852-08:00Add attribute on [Key] top of Primary column defin...Add attribute on [Key] top of Primary column defined for class<br /><br />[Table("tblEmployee")]<br /> public class Employee<br /> {<br /> [Key]<br /> public int EmployeeId { get; set; }Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-6082652835152798567.post-26714130849290765252018-12-02T11:32:36.945-08:002018-12-02T11:32:36.945-08:00Any one have problem when running the project with...Any one have problem when running the project with error 'NT AUTHORITY\IUSR' just Modify this line in your Web.config file like this in :<br /> Anonymoushttps://www.blogger.com/profile/11203483115950972487noreply@blogger.comtag:blogger.com,1999:blog-6082652835152798567.post-60914600044576263042018-07-31T01:45:17.327-07:002018-07-31T01:45:17.327-07:00System.InvalidOperationException: 'The specifi...System.InvalidOperationException: 'The specified cast from a materialized 'System.String' type to the 'System.Int32' type is not valid.'<br /><br />sir i was getting this error plese help me solve itchandanhttps://www.blogger.com/u/1/blogger.g?blogID=580049938277573339#allposts/src=sidebarnoreply@blogger.comtag:blogger.com,1999:blog-6082652835152798567.post-20107418756332811132018-06-18T23:21:00.739-07:002018-06-18T23:21:00.739-07:00Sr, can u plz explain how the selec query works he...Sr, can u plz explain how the selec query works here, i mean how column names are mappedAnonymoushttps://www.blogger.com/profile/16204035035434159118noreply@blogger.comtag:blogger.com,1999:blog-6082652835152798567.post-7909107697915899462018-04-05T06:31:32.081-07:002018-04-05T06:31:32.081-07:00Model Class [Employees.cs]
using System;
using Sy...Model Class [Employees.cs]<br /><br />using System;<br />using System.Collections.Generic;<br />using System.Linq;<br />using System.Web;<br />using System.ComponentModel.DataAnnotations.Schema;<br /><br />namespace WebApplication5.Models<br />{<br /> [Table("Table")]<br /> public class Employees<br /> {<br /> [key]<br /> public int Id { get; set; }<br /> public string Name { get; set; }<br /> public string Gender { get; set;}<br /> public string City { get; set; }<br /> }<br />}<br /><br />-------------<br /><br />Controller Class [EmployeeController.cs]<br /><br />using System;<br />using System.Collections.Generic;<br />using System.Linq;<br />using System.Web;<br />using System.Web.Mvc;<br />using WebApplication5.Models;<br /><br />namespace WebApplication5.Controllers<br />{<br /> public class EmployeeController : Controller<br /> {<br /> EmployeeDBEntities objEmployeeDBEntities = new EmployeeDBEntities();<br /> <br /> public ActionResult Index()<br /> {<br /> return View();<br /> }<br /><br /> public ActionResult Details(int id)<br /> {<br /> <br /> var data = objEmployeeDBEntities.Tables.Where(x => x.Id == id).ToList();<br /> EmployeeContext employeeContext = new EmployeeContext();<br /> ViewBag.data = data[0];<br /> return View(employeeContext);<br /> } <br /> }<br />}<br />------------------<br />Model Class [EmployeeContext.cs ]<br /><br />using System;<br />using System.Collections.Generic;<br />using System.Linq;<br />using System.Web;<br />using System.Data.Entity;<br /><br />namespace WebApplication5.Models<br />{<br /> public class EmployeeContext :DbContext<br /> {<br /> public DbSet Employees { get; set; }<br /> }<br />}<br />----------------------<br /><br />Global.asax.cs<br /><br />using System;<br />using System.Collections.Generic;<br />using System.Linq;<br />using System.Web;<br />using System.Web.Mvc;<br />using System.Web.Routing;<br />using System.Data.Entity;<br /><br />namespace WebApplication5<br />{<br /> public class MvcApplication : System.Web.HttpApplication<br /> {<br /> protected void Application_Start()<br /> {<br /> Database.SetInitializer(null);<br /> AreaRegistration.RegisterAllAreas();<br /> RouteConfig.RegisterRoutes(RouteTable.Routes);<br /> <br /> }<br /> }<br />}<br />-------------------------------------------------------------Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-6082652835152798567.post-14088632334941039952018-03-19T22:18:30.837-07:002018-03-19T22:18:30.837-07:00Hi venkatSir,
I am getting exception handler erro...Hi venkatSir,<br /><br />I am getting exception handler error at<br />Employee employee = EmployeeContext.Employees.Single(emp => emp.EmpId == id);<br /><br />an exception of type 'system.data.entity.core.entityexception' occurred in entityframework.sqlserver.dll but was not handled in user code additional information: the underlying provider failed on open.<br /><br />I am using visual studio 2012 and SSMS 2012 (My connection string was not created hence i added it explicitly as provided in part-8)Deepalihttps://www.blogger.com/profile/10010093386313241421noreply@blogger.comtag:blogger.com,1999:blog-6082652835152798567.post-24895314818817955222018-02-03T08:42:43.916-08:002018-02-03T08:42:43.916-08:00Hi I am facing the error:
The parameters dictiona...Hi I am facing the error:<br /><br />The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Details(Int32)' in 'MVCDemo1.Controllers.EmployeeController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.<br />Parameter name: parameters <br /><br />in Employee controller for this line of code I get the above error<br /><br />Employee employee = employeeContext.Employees.Single(x => x.EmpId == id);Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-6082652835152798567.post-80180333558561376922018-02-01T02:26:44.898-08:002018-02-01T02:26:44.898-08:00Hello,
I'm stuck from last two days facing the...Hello,<br />I'm stuck from last two days facing the exception.<br />I tried various solutions over the net, posted a question on stackoverflow but no luck please help me in this regard.<br />here is the link of question over stack over flow:<br />https://stackoverflow.com/questions/48548962/sql-server-browser-service-running-but-still-server-name-not-showing-in-vs2015<br /><br />And Here is the error i'm facing (not the complete error because not let me write more than 4096 characters):<br /><br />Message System.Data.Entity.Core.EntityException: The underlying provider failed on Open. ---> System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 25 - Connection string is not valid) ---> System.ComponentModel.Win32Exception: The parameter is incorrect --- End of inner exception stack traceInformaticshttps://www.blogger.com/profile/00652815790509949150noreply@blogger.comtag:blogger.com,1999:blog-6082652835152798567.post-67077491295975037552017-10-24T23:37:37.360-07:002017-10-24T23:37:37.360-07:00Thank you sir for your tutorial i followed part 8 ...Thank you sir for your tutorial i followed part 8 but i am getting an error :<br /><br />The model item passed into the dictionary is of type 'mvcdemo.Models.Employee', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[mvcdemo.Models.Employee]'.<br /><br />i have tried many times but it's not workingAkulosopherhttps://www.blogger.com/profile/10005382969859650736noreply@blogger.comtag:blogger.com,1999:blog-6082652835152798567.post-89783466954553396522017-10-06T10:16:44.420-07:002017-10-06T10:16:44.420-07:00Some how my post was cut off at connection to:... ...Some how my post was cut off at connection to:... Here is the connection string with username and password, and it should work updated the connectionString.<br />"Data Source = yourSQLHostName;Initial Catalog = Northwind; User Id=user1;Password=pass1;"<br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-6082652835152798567.post-87979978489110129032017-10-03T09:26:10.440-07:002017-10-03T09:26:10.440-07:00I was facing the problem with "The underlying...I was facing the problem with "The underlying provider failed on Open" error. I finally figured it out, so I thought to share this info which may help others. It looks like this error is related to security/authentication problem. The connectionString has "integrated security=SSPI" in which it will authenticate using current Windows credentials. If you were using the default ASP.NET to test without IIS, it would work. However, previous tutorial instructed us to using Local IIS, and this caused the authentication issues since IIS is not using your current Windows credentials (but "anonymous", I think). Here is the fix that worked for me, using Northwind database on MS SQL server as example:<br />1) Expand the database (Northwind).<br />2) Expand Security, and then Users<br />3) Make sure you have assigned a user to this database (e.g. username: user1 and password: pass1)<br />4) After that, go to your Web.Config file and change the connection to:<br /><br /><br />Hope it helps,Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-6082652835152798567.post-68606364811296955522017-09-23T04:40:29.937-07:002017-09-23T04:40:29.937-07:00Hi venkat how i can same thing with mysql databas...Hi venkat how i can same thing with mysql database 5.6karnjeethttps://www.blogger.com/profile/06525206398617920783noreply@blogger.comtag:blogger.com,1999:blog-6082652835152798567.post-46656750355440586022017-09-12T14:02:53.960-07:002017-09-12T14:02:53.960-07:00Hi Venkat,
i am facing below error.
An exception ...Hi Venkat,<br /><br />i am facing below error.<br />An exception of type 'System.Data.Entity.Core.EntityException' occurred in EntityFramework.SqlServer.dll but was not handled in user code<br /><br />Additional information: The underlying provider failed on Open.Anonymoushttps://www.blogger.com/profile/15701664725862791579noreply@blogger.comtag:blogger.com,1999:blog-6082652835152798567.post-14164257465021221722017-07-11T03:36:24.420-07:002017-07-11T03:36:24.420-07:00when i try to run same code it will give error.wha...when i try to run same code it will give error.what to do to fix this problem mr.venkat?<br />"An exception of type 'System.Data.ProviderIncompatibleException' occurred in EntityFramework.dll but was not handled in user code"Anonymoushttps://www.blogger.com/profile/11977178995510227274noreply@blogger.comtag:blogger.com,1999:blog-6082652835152798567.post-54039556233869385002017-07-07T04:06:59.878-07:002017-07-07T04:06:59.878-07:00public ActionResult Details(string EmployeeCode)
... public ActionResult Details(string EmployeeCode)<br /> {<br /> EmployeeContext employeecontext = new EmployeeContext();<br /><br /> Employee employee = employeecontext.Employees.Single(emp => emp.Employee_Code == EmployeeCode);<br /><br /> return View(employee);<br /><br /> //Employee employee = new Employee()<br /> //{<br /> // Employee_Code = "00620",<br /> // //First_Name = "Alagu",<br /> // Employee_Name = "Alagu Ganesh A",<br /> // DOJ = "Feb 26, 2009",<br /> // //Confirm_Date = "Feb 26, 2009",<br /> // Actl_Confirm_Date = "Jul 01, 2011",<br /> // Designation = "Team Lead - ERP Development",<br /> // Department = "Corporate - Support",<br /> // //Cost_Center = "Corporate - Support",<br /> // //Grade_Code = "B6C2",<br /> // Location = "CHENNAI",<br /> // State_Name = "Tamil Nadu",<br /> // Supervisor_Code = "00986",<br /> // Supervisor_Name = "Suresh Gopal"<br /> //};<br /><br /> //return View(employee);<br /> }<br /><br />Dear Venkat,<br /><br />I'm Alagu Ganesh and I'm using your code but the input is not int its is string you can see that in this email.<br /><br />I'm compile this and I'm getting this error. <br /><br />"Sequence contains no elements"<br /><br />Line 17: Employee employee = employeecontext.Employees.Single(emp => emp.Employee_Code == EmployeeCode);<br /><br />please check and help me to fix this error.<br /><br />your blog and your you-tube videos are very help full and I'm learning lot of new software language.<br /><br />Thanks & regards,<br />Alagu Ganesh<br /><br />A Alagu Ganeshhttps://www.blogger.com/profile/00652258837093958750noreply@blogger.comtag:blogger.com,1999:blog-6082652835152798567.post-79318421570619535822017-06-13T05:01:56.243-07:002017-06-13T05:01:56.243-07:00Additional information: The underlying provider fa...Additional information: The underlying provider failed on Open.<br />plz help ..Anonymoushttps://www.blogger.com/profile/01504675094679873492noreply@blogger.comtag:blogger.com,1999:blog-6082652835152798567.post-22206437691996570392017-05-17T12:11:08.072-07:002017-05-17T12:11:08.072-07:00an exception of type 'system.data.entity.core....an exception of type 'system.data.entity.core.entityexception' occurred in entityframework.sqlserver.dll but was not handled in user code additional information: the underlying provider failed on open.<br /><br /><br />pls help me sirAnonymoushttps://www.blogger.com/profile/11855233439724052402noreply@blogger.comtag:blogger.com,1999:blog-6082652835152798567.post-84748335849543931372017-04-01T09:58:08.628-07:002017-04-01T09:58:08.628-07:00Line 27: //};
Line 28: Employee...Line 27: //};<br />Line 28: EmployeeContext EmployeeContext = new EmployeeContext();<br />Line 29: Employee emp = EmployeeContext.Employees.Single(x => x.EmpId == id);//here its throwing an exception<br />Line 30: return View("employee", emp);<br />Line 31: //Employee employee = EmployeeContext.Employee.Single(emp => emp.empId == id);<br /><br /><br /><br /> Exception Details: System.Data.Entity.ModelConfiguration.ModelValidationException: One or more validation errors were detected during model generation:<br /><br />MvcApplication1.Models.Employee: : EntityType 'Employee' has no key defined. Define the key for this EntityType.<br />Employees: EntityType: EntitySet 'Employees' is based on type 'Employee' that has no keys defined.Anonymoushttps://www.blogger.com/profile/05051442322771803966noreply@blogger.comtag:blogger.com,1999:blog-6082652835152798567.post-28136957449048313832017-03-06T00:57:48.900-08:002017-03-06T00:57:48.900-08:00I have same issue
Server Error in '/' App...I have same issue <br />Server Error in '/' Application.<br /><br />One or more validation errors were detected during model generation:<br /><br />learn_MVC.Models.Details: : EntityType 'Details' has no key defined. Define the key for this EntityType.<br />Detailss: EntityType: EntitySet 'Detailss' is based on type 'Details' that has no keys defined.<br /><br />Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. <br /><br />Exception Details: System.Data.Entity.ModelConfiguration.ModelValidationException: One or more validation errors were detected during model generation:<br /><br />learn_MVC.Models.Details: : EntityType 'Details' has no key defined. Define the key for this EntityType.<br />Detailss: EntityType: EntitySet 'Detailss' is based on type 'Details' that has no keys defined.<br />kindly someone help meAnonymoushttps://www.blogger.com/profile/18138338211304499748noreply@blogger.comtag:blogger.com,1999:blog-6082652835152798567.post-1108815360366415612017-02-02T03:18:44.474-08:002017-02-02T03:18:44.474-08:00Can we use Access Database instead of SQL server d...Can we use Access Database instead of SQL server database?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-6082652835152798567.post-63345103014173938682016-11-30T13:26:42.216-08:002016-11-30T13:26:42.216-08:00EmployeeContext should be inherited by DbContext.
...EmployeeContext should be inherited by DbContext.<br /><br />I believe u have already figured it out.<br /><br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-6082652835152798567.post-15992690419541003122016-10-19T02:11:34.322-07:002016-10-19T02:11:34.322-07:00"The system cannot find the file specified&qu..."The system cannot find the file specified" error is coming while running my application,shows error at that line "Employee employee = employeecontext.Employees.Single(emp => emp.Employeeid == id);". DOnt kow what to do.Anonymoushttps://www.blogger.com/profile/12352615205505460659noreply@blogger.com