|
|
Hello, i followed this example to Create an application, so i have in my DB, a table account and a table role and the relation ship between account and role is many to many, so i have a association table account_role, i work with EF database first and i generate my POCO with EF DbContext Generator, i want an edit Account page dispay a checkbox ,My Problem is the checkbox does not retain its state and also each time when I click the save button it removes the added roles (choose)
Since this is not a question that is about the sample code or the tutorial, please post your question along with samples of your code to the ASP.NET forum: http://forums.asp.net/1227.asp x/1?ADO+NET+Ent ity+Framework+L INQ+to+SQL+NHib ernate
Thank you Tom Dykstra for your answer, i posted My thread in http://forums.asp.net/t/178518 5.aspx/1?Asp+MV C3+checkbox+doe s+not+retain+it s+state But i don't find a valid answer thank you to help me
I get an "Operation could destabilize the runtime" exception when running the code on my computer with both VS2010 and VS2012. On another computer with only VS2010 I have no issues. Server Error in '/' Application. ------------------------------ --------------- --------------- --------------- ----- Operation could destabilize the runtime. 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.Security .VerificationEx ception: Operation could destabilize the runtime. Source Error: Line 72: int pageSize = 3; Line 73: int pageNumber = (page ?? 1); Line 74: return View(students.T oPagedList(page Number, pageSize)); Line 75: } Line 76: Source File: C:\MSDN\Demo\C# \ContosoUnivers ity\Controllers \StudentControl ler.cs Line: 74
The problem appears to be an incompatibility with VS 2012 in the PagedList NuGet package. Updating the package resolves the error. I'll upload a new version of the project with the updated package.
In the tutorial we create a generic repository to integrate the UnitOfWork but you also say that we should create Interfaces and repositories for the rest of the models if we are going use TDD. How this repositories interfaces would integrate with the generic repository? Or they dont integrate and only exist for TDD use? Thanks and it was a great tutorial.
You would create one interface for the generic repository the same way you create one interface for each non-generic repository, and one interface for the unit of work class. You would then call the generic repository through the interface, as you would with the non-generic repositories. In other words, if you create the generic repository to handle 5 different entities, you don't create 5 interfaces, you just create one for the generic repository. But if you create a derived class from the generic repository to handle special needs for one entity, you would create an interface for that also.
First off, this is an awesome example. I have downloaded this and the pure ASP.NET Web Pages sample. Why does this sample not have an example of Unit Testing whereas the Web Pages sample does? I am developing an MVC 3 application for my business and used about 75% of the code in here, but ended up using code from the MVC 3 book from Steve Sanderson because he had unit testing included. I love the PagedList in ContosoUniversity, but not sure how to use it for unit tests. Anywhere else that has the ContosoUniversi ty example with a unit test or 2 that I can go to and check out? Thanks for a great example!
I'm glad to hear that you've found the sample helpful. I don't remember now why we decided not to include unit testing in the MVC series, but I suspect it was because it was already getting fairly long and unit testing seemed relatively peripheral to the main goal of showing how to use Entity Framework. We are currently prioritizing work for the remainder of this year, and updating this tutorial series is one of the tasks being considered. I'll add unit testing as one of the proposed enhancements when we update, but it's unsure right now how much time is available for that or if it might get delayed again by higher priority work.
I'm sure it is me somehow, but I am just trying to get this to work on my VS 2010 Prof edition but keep getting this error: "Unable to find the requested .Net Framework Data Provider. It may not be installed." I have SQLExpress and SQL CE installed so I don't know what else could be wrong. Also, when I look in the app_data folder, the db doesn't show up??? I don't see the mdf. In the physical dir I see sdf. I always have terrible luck with these db files, so please help me out. I've tried both the VB and C# versions, both do not work on my VS 2010. Am I missing the mdf?
You should only need SQL Compact to be installed. One thing you might try, though, in case there's some problem with your installation of SQL Compact, is to install the EF NuGet packages in the project. The NuGet package names are SQL ServerCompact, EntityFramework, and EntityFramework .SqlServerCompa ct.
Could you tell me that where does the code set the Primary key for table Department?
The class did not have a attribute for the property DepartmentID.
------------
public class Department
{
public int DepartmentID { get; set; }
[Required(Error Message = "Department name is required.")]
[MaxLength(50)]
public string Name { get; set; }
[DisplayFormat( DataFormatStrin g = "{0:c}")]
[Required(Error Message = "Budget is required.")]
[Column(TypeNam e = "money")]
public decimal? Budget { get; set; }
[DisplayFormat( DataFormatStrin g = "{0:d}", ApplyFormatInEd itMode = true)]
[Required(Error Message = "Start date is required.")]
public DateTime StartDate { get; set; }
[Display(Name = "Administrator" )]
public int? PersonID { get; set; }
[Timestamp]
public Byte[] Timestamp { get; set; }
public virtual Instructor Administrator { get; set; }
public virtual ICollection<Cou rse> Courses { get; set; }
}
--------------- ------
This is explained in the first tutorial (http://www.asp.net/mvc/tutori als/getting-sta rted-with-ef-us ing-mvc/creatin g-an-entity-fra mework-data-mod el-for-an-asp-n et-mvc-applicat ion): it's an EF Code First convention that the a property named classname + ID or just ID is interpreted as the primary key.
Thank you,Tom Dykstra! I am sorry about that i did not read the whole Tutorials.
i have requirerment like: filter using two columns with "OR" condion for example: Student Number,department Name records for specified department including the record for that student number specified if department is different needs to be displayed.... for this how can i customize lamda expression in my generic repository...
For questions that aren't about actual code in the project or the tutorials, the best place to get specific answers would be the ASP.NET EF forum (http://forums.asp.net/1227.as px) or StackOverflow.c om.
In this proj.. we have get method with three arguments in GenericRepository, similar way i need one method i was not familier with lamda expressions thats why...i am facing the problem...
For an excellent introduction to lambda expressions, see this book chapter that is posted in several places on the internet: http://www.informit.com/articl es/article.aspx ?p=1570280
Tom, Thank You very much... i have basic idea for EF code First Approch but i want strong knowledge on that, please help me out..
Hi Tom, I was reading your tutorial and I read this comment "(This class is in the Models namespace, because in some situations Code First assumes that the entity classes and the context class are in the same namespace.)" and I was wondering if you could tell in which situations this is needed or maybe point me to some article or doc where this is explained in more detail? Thanks for your input on this! Nice tut BTW!!!
Hi Aloaiza, This issue was reported as a bug to the Entity Framework team, but was not reported as an issue by enough customers for them to prioritize it high enough to investigate further, and so its precise causes remain unknown. It seems to be a combination of factors within EF and outside of EF, because you can load the exact same project on two different machines, and in one you don't have the namespace confusion bug and on the other you get it. When I created the tutorial everything worked fine, then some of the first customers to use the tutorial reported a problem, and so I tried it on several different machines, and on some machines I got the same error they did. I found this way of ensuring that the error did not occur on any of the machines and changed the tutorial to reflect that workaround. There is a known bug in EF that makes it impossible to have the same class in different namespaces in the same assembly, but this does not seem to be related to that bug. Tom
I change the code to viewModel.Instructors = db.Instructors .Include(i => i.OfficeAssignm ent) .Include(i => i.Courses.Selec t(c => c.Department)) .OrderBy(i => i.LastName); and got the error Server Error in '/' Application. --------------- --------------- --------------- --------------- --------------- ----- The ResultType of the specified expression is not compatible with the required type. The expression ResultType is 'Transient.refe rence[ContosoUn iversity.Models .Person]' but the required type is 'Transient.refe rence[ContosoUn iversity.Models .Instructor]'. Parameter name: arguments[0] 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.Argument Exception: The ResultType of the specified expression is not compatible with the required type. The expression ResultType is 'Transient.refe rence[ContosoUn iversity.Models .Person]' but the required type is 'Transient.refe rence[ContosoUn iversity.Models .Instructor]'. Parameter name: arguments[0] Source Error: Line 19: <th>Courses</th > Line 20: </tr> Line 21: @foreach (var item in Model.Instructo rs) Line 22: { Line 23: string selectedRow = ""; Source File: h:\sharefolder\ yangyi\PublishT emp\Views\Instr uctor\Index.csh tml Line: 21 Stack Trace: [ArgumentExcept ion: The ResultType of the specified expression is not compatible with the required type. The expression ResultType is 'Transient.refe rence[ContosoUn iversity.Models .Person]' but the required type is 'Transient.refe rence[ContosoUn iversity.Models .Instructor]'. Parameter name: arguments[0]]
My ConnectString is <add name="SchoolContext" providerName="S ystem.Data.SqlC lient" connectionStrin g="Server=.;Dat abase=School;Us er id=sa;Password= sa;"/> Is there something wrong?
This tutorial: http://www.asp.net/mvc/tutoria ls/getting-star ted-with-ef-usi ng-mvc/implemen ting-inheritanc e-with-the-enti ty-framework-in -an-asp-net-mvc -application explains that this does not work due to a bug in the current version of EF: The current version of the Entity Framework doesn't support eager loading for one-to-zero-or- one relationships when the navigation property is on the derived class of a TPH inheritance structure. This is the case with the OfficeAssignmen t property on the Instructor entity.
This application is really great and it is a complete package that helps in learning EF and MVC quickly without having to read hundreds of pages of a book (and get lost in the middle) just to get started. I may still have to read the book if I need to go into details, but this tutorial is very good for a beginner and I like the way the concepts are explained with examples and code snippets. however it would have been more helpful if this application had some amount of business logic in it as well to make it more close to a real world application. I think EF 4.1 allows us to implement business logic using partial classes (though its main purpose is data management), I would like to see it in action if possible. it will be useful if it demonstrates how to implement business logic (not just a simple validation using annotations) within an entity and across multiple entities. Thanks in advance.
Thank you for the suggestion - I'll add that to the list of things we should consider for the next release of the tutorials that this project accompanies. We don't have a projected release date for that update yet.