|
|
Can I use this application with * Visual Studio 2008 * SQL Server 2008 Enterprise Edition
You can use it with SQL Server 2008 with a different connection string, but it requires Visual Studio 2010 and ASP.NET 4.
The application is set up to use SQL Server Compact; if you want to use SQL Server Express instead, all you have to do is remove the SchoolContext connection string from the Web.config file and a SQL Server Express database will be created automatically. If you want to use full SQL Server you will need to change the SchoolContext connection string to point to the SQL Server instance you want to use.
If you want to use full SQL Server ,but I don't know how to change the SchoolContext connection string . Link this? <add name="SchoolContext" connectionStrin g="metadata=res ://*/DAL.School Model.csdl|res: //*/DAL.SchoolM odel.ssdl|res:/ /*/DAL.SchoolMo del.msl;provide r=System.Data.S qlClient;provid er connection string="Da ta Source=.\;Initi al Catalog=School; user id=sa;Password= 123;MultipleAct iveResultSets=T rue"" providerName="S ystem.Data.Enti tyClient" />
Your example look like a Database First connection string. You should be able to use a normal SQL Server connection string (i.e., without .csdl/.ssdl/.msl etc.) with Code First. For more information on connection strings see this site: http://www.conn ectionstrings.c om/
I chang the SchoolContext connection string like this:
<add name="SchoolCon text"
connectionStrin g="data source=.\;Initi al Catalog=School; user id=sa;Password= 35683568;"
providerName="S ystem.Data.SqlC lient" />
But Error Like this:
Model compatibility cannot be checked because the database does not contain model metadata. Ensure that IncludeMetadata Convention has been added to the DbModelBuilder conventions.
The database School is worked well,but I just don't know how to change the connection string.
See this forum thread which is about the same error message: http://forums.asp.net/p/167337 9/4385705.aspx If the cause in your case is different, I'm not familiar with it and I would recommend posing a question on StackOverflow or the ASP.NET forum.
Happy to see that! And Thank you for sharing your solution to us! That must be very useful!
This happens @ var databaseValues = (Department)entry.GetDatabaseV alues().ToObjec t(); The exception is: Type 'ContosoUnivers ity.DAL.Departm ent' could not be found. Make sure that the required schemas are loaded and that the namespaces are imported correctly. Near type name, line 1, column 128. How can this be resolved? Thanks! Dave
In the project on my machine, Department resolves correctly to ContosoUniversity.Models.Depar tment. You could make that explicit in yours by changing Department to ContosoUniversi ty.Models.Depar tment, but I don't know why it would resolve differently on your machine.
You can eliminate the error by changing the SchoolContext class to be in the ContosoUniversity.Models namespace. This should not be necessary and I am still following up with the Entity Framework team, but that will get the code to work. You will have to add using statements for the Models namespace to Global.asax.cs and HomeController. cs.
Since it is taking some time to find out the cause of this bug and there may not be a fix available immediately for it anyway, I have changed the tutorial and the project to put the context class in the Models namespace. On all machines that I've been able to repro the error this fixes it.
I just downloaded and compiled the source and I'm getting the same error DBuckner is getting. If you debug and look at the non-public members of the entry variable, you'll see InternalEntry.EdmEntityType = {ContosoUnivers ity.DAL.Departm ent}. Is there some configuration that can be done in the OnModelCreating method in SchoolContext?
Thank you for the additional information. I'm trying to get a machine set up that repros the problem and will follow up with a solution as soon as I can find out what is going on. My guess is that this could be resolved by moving the context class and possibly also the initializer class into the Models namespace, but that should not be necessary.
I've been able to repro the problem and am following up with the Entity Framework team.
You can eliminate the error by changing the SchoolContext class to be in the ContosoUniversity.Models namespace. This should not be necessary and I am still following up with the Entity Framework team, but that will get the code to work. You will have to add using statements for the Models namespace to Global.asax.cs and HomeController. cs.