database-first

Best way to approach tying in Entity Framework 4 (“Database First”) and MVC3

这一生的挚爱 提交于 2019-12-04 11:05:54
I am a relative newcomer for C#.Net (.net 4), EF4, Winforms, and MVC3. I had laid out a database in SQL Server in the process of developing a Winforms "backend" for a task I have been assigned. I setup a single Solution and created a .edmx from the database as its own project/assembly in the solution. Also in the solution is the winforms app that references the .edmx assembly. Using the default EF4 code generation, I built out the Winforms app and all is well there. Now, I have to build out the enduser web frontend. I want to use MVC3. I have been through MVC3 tutorials on Pluralsight and

MVC DB first Fix display Name

百般思念 提交于 2019-12-03 16:36:34
问题 I'm using mvc 4, with database first. Everytime I refresh the model.edmx file, the display name attribute I added is removed. How can I the keep display name attribute between refreshes? 回答1: You are going to want to use System.ComponentModel.DataAnnotations . Here is a simplistic Example for a 'User' table in EF to show you how: namespace YourNamespace.BlaBlaBla { [MetadataType(typeof(UserHelper))] public partial class User { } public class UserHelper { [Display(Name = "Your New Title For

Is there a way to change connection string in database first?

落花浮王杯 提交于 2019-12-03 11:47:22
问题 I have several databases, the schema of them are same. When I use database-first, the connection string is specified when I create the edmx file. I want to know, is there a way to change the connection string? This is, so I can choose which database to operate. Thx in advance! 回答1: Change the connection string in the web.config file. <connectionStrings> <add name="SandBoxEntities" connectionString="metadata=r... /> </connectionStrings> I abbreviated the actual connection string because it isn

Adding a New Column to an Existing Table in Entity Framework

≯℡__Kan透↙ 提交于 2019-12-03 11:36:10
问题 I have added a new column to a table in my database. The table is already defined in the existing Entity Framework model. I've been through most of the items here on how to do this and it still fails. A little background, this entity model has not been updated in at least 3 years. So aside from the column I'm adding I know there have been a number of other columns that have been added in that time, but never included. I took over the project about 9 months ago and have never been able to

MVC DB first Fix display Name

浪尽此生 提交于 2019-12-03 06:42:32
I'm using mvc 4, with database first. Everytime I refresh the model.edmx file, the display name attribute I added is removed. How can I the keep display name attribute between refreshes? You are going to want to use System.ComponentModel.DataAnnotations . Here is a simplistic Example for a 'User' table in EF to show you how: namespace YourNamespace.BlaBlaBla { [MetadataType(typeof(UserHelper))] public partial class User { } public class UserHelper { [Display(Name = "Your New Title For Name")] public string Name { get; set; } } } You can also include validation in your class as well. Be sure it

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

Is there a way to change connection string in database first?

a 夏天 提交于 2019-12-03 02:04:54
I have several databases, the schema of them are same. When I use database-first, the connection string is specified when I create the edmx file. I want to know, is there a way to change the connection string? This is, so I can choose which database to operate. Thx in advance! Change the connection string in the web.config file. <connectionStrings> <add name="SandBoxEntities" connectionString="metadata=r... /> </connectionStrings> I abbreviated the actual connection string because it isn't important -- just wanted to give you an idea of what to look for in the web.config file. You can also

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

Code First vs. Database First

强颜欢笑 提交于 2019-11-30 04:46:44
I created an Entity Framework model based on an existing database, then generated the POCO entities from the model. The connection string in my web.config isn't Entity Framework, it's just the standard connection string (it's missing the CSDL, SSDL, MSL references). I can compile my application, but when I run I get this error: Code generated using the T4 templates for Database First and Model First development may not work correctly if used in Code First mode. To continue using Database First or Model First ensure that the Entity Framework connection string is specified in the config file of

Entity Framework cant use the DbContext, model being created

霸气de小男生 提交于 2019-11-28 12:06:00
I am using EF 4.1, and I create a normal EF edmx file. I generate it from a DB. When it's been generated I rightclick and select add code generation item, to generate new classes, and use the DbContext instead. I use the template DbContext generator. Everything works fine. Then I trie to query the context: using (var context = new PasDBEntities()) { var client=context.ClientCompanies.SingleOrDefault(_=>_.ID==clientCompanyId); if(client!=null) I have no problem creating a new instance of the context but when I try to query it the problem occur. I get stuck on the UnintentionalCodeFirstException