Hi Tom: When I tried to run your application, everything worked until it tried to attach the file CU10.mdf to the database whereupon it choked. I couldn't find this file anywhere in the download. Am I missing something? Roger S
Whoops - I guess my local system doesn't handle attach well - removed that from the connection strings and database built like a charm - thanks - looking forward to going though this. Roger
I too encountered this error in the Package Manager after running 'Update-Databas
e' to set up the project. The error I received was: Cannot attach the file 'C:\Users\Rich\ Documents\Visua l Studio 2013\Projects\E FCF\C#\ContosoU niversity\App_D ata\CU10.mdf' as database 'CU10'. The reason for this was that I had previously set the solution up and an instance of the CU10 database was already attached. To resolve I logged into the '(LocalDB\v11.0 )' dataabse in SQL Server Management Studio and deleted the CU10 database that was there. I reran the command and all is well once again in LaLa Land.
Hi Tom, as described in "MVC ModelBinding Vulnerability in Contoso University sample (first raw PoC)" http://blog.din
iscruz.com/2013 /07/mvc-modelbi nding-vulnerabi lity-in.html there are a number of MVC ModelBinding Vulnerabilities in this application. I would like to use this application has an example of how to fix these issues, so have you added this code to GitHub? (so that I can fork it and make my code changes there?)
We've updated the application both here in Code Gallery and on the archive.msdn site where the chapter downloads are stored. I'm not aware that there is a copy of this project on GitHub -- if someone has put one there I don't have control over it. The download project shows one method to address the vulnerability - using the Bind attribute. Another method is to use view models and not bind directly to entity classes. The options are discussed in a new security note sidebar in tutorial #2.
I believe it is better to rely on the available links in Gallery MSDN
I have the E-Book "Getting Started with the Entity Framework 4.1 Using ASP.NET MVC".pdf which states that the requirements are VS 2010 SP1. I've fulfilled that and the other requirements. However, the link "download the completed application" brings me HERE and the requirements to create, build and run the sample are now different. So, where is the source code to the VS 2010 MVC 3 version? I don't WANT to build the "latest" version - for a SPECIFIC REASON.
Here's a link to the C# MVC 3 project: http://archive.
msdn.microsoft. com/Project/Dow nload/FileDownl oad.aspx?Projec tName=aspnetmsd nexamples&Downl oadId=16474 We forgot to re-post the old version somewhere when we updated the sample for MVC 4 EF 5.
Thank you, Tom. Much appreciated.
I like your app so much and your work is highly appreciated. I just have two questions for you: In Department controller: 1-private SchoolContext db = new SchoolContext()
; how the database connection(from web.config) is passed to schoolcontext instance 2-in index action, you use db.department Where is department initialized? Thank you in advance
1. EF looks for a connection string with the same name as the context class. See the first tutorial in the series for more information about this. 2. Departments DbSet property is defined in the context class. See the first and fourth tutorials in the series for more information about this.
Hi Sir I downloaded solution file and restore it using package manager console.After that i ran the update-database command.but i got an following error --'Cannot find the object "dbo.Student" because it does not exist or you do not have permissions.''' Please givethe answer
Make sure you have the right software installed. See the Prerequisites section of the first tutorial in the series: http://www.asp.
net/mvc/tutoria ls/getting-star ted-with-ef-usi ng-mvc/creating -an-entity-fram ework-data-mode l-for-an-asp-ne t-mvc-applicati on Also make sure that you follow the instructions for downloading and running the application. See the Downloading and Building page at: http://www.asp. net/mvc/tutoria ls/getting-star ted-with-ef-usi ng-mvc/building -the-ef5-mvc4-c hapter-download s
Hi Sir, i downloaded source code and learn how it works i insert a student its successfully insert and also populate in list but i am not bale to see data coming from and insert please help me.
What do you mean by "not able to see data coming from and insert", can you explain a little more about where you're looking for data and not seeing it?
i added one student but that student are not showing in DAL/SchollIniti
liazers.cs file while all student which is already in the system are there but whose i added it's not showing in this file so i have my Q where does he go please help me
thanks for reply i am getting the answer of my Q i read your code documentation sir can you help me how to learn mvc with entity framework i mean what will be the best way to learn and implementation
See the tutorial that goes with the download: http://www.asp.
net/mvc/tutoria ls/getting-star ted-with-ef-usi ng-mvc/creating -an-entity-fram ework-data-mode l-for-an-asp-ne t-mvc-applicati on When you add students using the UI they won't go into the seed method code, they'll go into the database; see the tutorial for more information about the seed method and what it's for.
Hi- You have a typo in config file: \C#\ContosoUniv
ersity\Web.conf ig It should have a backslash in front of the data file name, like this: connectionStrin g="Data Source=|DataDir ectory|\School. sdf" Thanks for creating this-
Thanks for reporting that, but since both formats work, why do you consider omitting the backslash to be a typo?
Hi, I have some 3rd party Dlls(x64) which i am trying to use with this application, if i change the target platform of thsi application to x64, it fails with the following exception Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace: [BadImageFormat
Exception: Could not load file or assembly 'ContosoUnivers ity' or one of its dependencies. An attempt was made to load a program with an incorrect format.] System.Reflecti on.RuntimeAssem bly._nLoad(Asse mblyName fileName, String codeBase, Evidence assemblySecurit y, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotF ound, Boolean forIntrospectio n, Boolean suppressSecurit yChecks) +0 System.Reflecti on.RuntimeAssem bly.nLoad(Assem blyName fileName, String codeBase, Evidence assemblySecurit y, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotF ound, Boolean forIntrospectio n, Boolean suppressSecurit yChecks) +39 System.Reflecti on.RuntimeAssem bly.InternalLoa dAssemblyName(A ssemblyName assemblyRef, Evidence assemblySecurit y, StackCrawlMark& stackMark, Boolean forIntrospectio n, Boolean suppressSecurit yChecks) +132 System.Reflecti on.RuntimeAssem bly.InternalLoa d(String assemblyString, Evidence assemblySecurit y, StackCrawlMark& stackMark, Boolean forIntrospectio n) +144 System.Reflecti on.Assembly.Loa d(String assemblyString) +28 System.Web.Conf iguration.Compi lationSection.L oadAssemblyHelp er(String assemblyName, Boolean starDirective) +46 are these any native x86 dlls refered in thge project, is there any way i can use this project tagetting x64 platform
I don't know the answer to that; I suggest posting a question to a forum or StackOverflow.c
Hi, I'm unable to get the Search feature to work. I get the error below. Any suggestions? Server Error in '/' Application. The resource cannot be found. Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly. Requested URL: /Student Version Information: Microsoft .NET Framework Version:4.0.303
19; ASP.NET Version:4.0.303 19.18044
Does this happen while working through the tutorial, or when you download and run the completed project? If you're going through the tutorial, you can download the completed project and compare the code to what you built manually to see if you missed a step somewhere.
The primary key value cannot be deleted because references to this key still exist. [ Foreign key constraint name = Department_Admi
nistrator ] 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. Exception Details: System.Data.Sql ServerCe.SqlCeE xception: The primary key value cannot be deleted because references to this key still exist. [ Foreign key constraint name = Department_Admi nistrator ] Source Error: Line 198: Instructor instructor = db.Instructors. Find(id); Line 199: db.Instructors. Remove(instruct or); Line 200: db.SaveChanges( ); Line 201: return RedirectToActio n("Index"); Line 202: }
Since the constraint is Department_Admi
nistrator, I would look in the Department table, PersonID column, for the instructor ID of the instructor you want to delete, then change Department.Pers onID to null before you delete the instructor.