ef-database-first

MVC3 and EF Data first: what are the best practices?

邮差的信 提交于 2019-12-03 06:18:55
问题 It seems that most of the focus with MVC3 and EF4.1 is around "code first" - I can't seem to find any examples or tutorials that meet the following criteria: uses an existing SQLServer database has separate projects for web & data access (we will have multiple web apps sharing the same data access classes) recommendations for validation Does such an example or tutorial exist? Are there any documented "best practices" for how to accomplish this, or rationale for NOT having a solution

Entity Framework 5, switch from code first to database first?

旧城冷巷雨未停 提交于 2019-12-03 03:44:12
I've already created a database using code first. It worked well. Many changes have since been made to the database outside Visual Studio. So many that any attempt at migration generates errors. So my question is, is there a way to switch a solution from code first to database first? This should be easy, just create a new, database first model and delete your code first model. Most of your code will compile just fine if you are in the same namespace and take care of naming your context in the same way. Switching to database first however, makes you lose the ability to migrate which is a solid

MVC3 and EF Data first: what are the best practices?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-02 19:42:33
It seems that most of the focus with MVC3 and EF4.1 is around "code first" - I can't seem to find any examples or tutorials that meet the following criteria: uses an existing SQLServer database has separate projects for web & data access (we will have multiple web apps sharing the same data access classes) recommendations for validation Does such an example or tutorial exist? Are there any documented "best practices" for how to accomplish this, or rationale for NOT having a solution structured this way? Ladislav Mrnka It is quite common scenario and it depends if you want to use EDMX file for

Getting error on POST with Entity Framework - Value cannot be null. Parameter name: source

╄→гoц情女王★ 提交于 2019-12-02 06:42:50
EDIT - as requested, this is the view... --start edit @model salesWebTest.viewModel.vwbooking @using (Html.BeginForm()) { @Html.AntiForgeryToken() @Html.ValidationSummary(true) @Html.HiddenFor(model => model.bookings.bookingid) @Html.EditorFor(model => model.bookings.name) @foreach (var item in Model.traces) { @Html.EditorFor(m => item.contact_Name) } } --end edit --start original question I have a viewModel that contains two classes... public class vwbooking { public booking bookings { get; set; } public IEnumerable<trace> traces { get; set; } } Booking and trace are entities in an edmx. I

How to combine both of code first and database first approaches

ぃ、小莉子 提交于 2019-12-02 04:50:48
Let's say I'm a new developer in a company. So there is already an existing database for the project. To work on the project, obviously I need to scaffold the existing database(database first approach), which can generate model classes for me to work on. So I start to work on the project and want to add a new column to a table, so I add a new property on the model class then I want to apply this change in the database. So I switch back to code first approach by adding a new migration and update the database. But the problem is, if I add a new migration, EF will include all the data model

Add relationships to the ApplicationUser class in ASP.NET Identity (Database First)

依然范特西╮ 提交于 2019-12-01 23:43:02
问题 I'm using ASP.NET Identity (Database First) in my ASP.NET MVC application. I followed the instructions here, to set up the ASP.NET Identity with database first approach. My AspNetUsers table has a relationship with the Employee table (The Employee table has a UserId foreign key, and the AspNetUsers entity has an ICollection<Employee> property). I would like to add the ICollection<Employee> property to the ApplicationUser, like below: public class ApplicationUser : IdentityUser<int,

ef5 database first data annotation

隐身守侯 提交于 2019-12-01 22:32:24
问题 I am starting MVC4 with VS2012. I am also using EF5 with the "Database First" method of creating my classes. However because the generated glasses can be regenerated I cannot put the Data Annotation details to assist with validation. I have seen some code snippets that use MetaData and partial classes but I was wondering if anyone knows of a small compilable example that I can look at and pull apart to better understand how the vasious classes interlink. Many many thanks for any help. Dave

SimpleMembershipInitializer won't initialize

你。 提交于 2019-12-01 16:07:15
I am struggling with getting a simplemembership scenario working in my EntityFramework / MVC4 / DatabaseFirst project. I've found plenty of examples for working with code first, but nothing for DB first. The problem I'm encountering is the the InitializeDatabaseConnection is throwing an error ("Unable to find the requested .Net Framework Data Provider. It may not be installed.") The code looks like this : WebSecurity.InitializeDatabaseConnection("DALEntities", "tblContacts1", "ContactID", "EMail", autoCreateTables: true); I am not sure what DataProvider is failing. If I try to trace 'into' the

IManifestTokenResolver for Database First Model?

坚强是说给别人听的谎言 提交于 2019-12-01 12:53:30
We need an option to set the ProviderManifestToken in code for a Database First Model in order to override the value from the EDMX, which defaults to "2012" for SQL Server 2012 in our particular case. What we've tried so far: As described in this post we decorated our context class with the DbConfigurationType attribute, our derived class looks exactly the same as in that post. internal sealed class MyDbConfiguration : DbConfiguration { public MyDbConfiguration() { //this.AddDependencyResolver(new SingletonDependencyResolver<IManifestTokenResolver>(new ManifestTokenService())); this

How should I define a composite primary key for an existing database table?

可紊 提交于 2019-12-01 06:50:41
问题 I'm working on a Core MVC project that reads data (no writing required) from a pre-existing database. Unfortunately this database is a total mess, but I cannot change anything in it (and even if I could, I wouldn't touch it with a 10-foot pole). Some of the relevant problems of the database are the following: The tables don't have any foreign key relations to each other, and contain data that would have best been entered into a sub-table; whoever created the database seems to have used tables