ef-database-first

DB default value ignored when creating Entity Framework model

ぐ巨炮叔叔 提交于 2019-12-01 04:48:04
问题 Assuming I have the following table in my DB: CREATE TABLE [dbo].[Test] ( [Id] INT IDENTITY (1, 1) NOT NULL, [Active] BIT DEFAULT ((1)) NOT NULL, ) When creating an EF model from this DB, the mapping for the Active bit column , which is mapped to a Boolean column, has no default value (see property "Default Value): Why does Entity Framework behave that way? Why doesn't the default value that is defined in the database automatically be applied in the model when the model gets created? The DB

Entity Framework 4.1 Database First does not add a primary key to the DbContext T4 generated class

强颜欢笑 提交于 2019-12-01 04:12:36
I am just getting started with Entity Framework 4.1, trying out the "database first" mode. When EF generates a Model class with the "ADO.Net DbContext Generator," shouldn't it identify the primary key for the class with a [Key] attribute? Without this, it appears incompatible with the T4 MVCScaffolding. Here are the details: Using the Entity Data Model Designer GUI, I have added a simple "country" table to the model from my existing database. The GUI correctly identifies a single integer identity key field named "PK" as my primary key. (Alas! I'm a new user so I can't add a screenshot. I've

Unable to retrieve project metadata. Ensure it's an MSBuild-based .NET Core project

六月ゝ 毕业季﹏ 提交于 2019-12-01 03:52:33
I've been researching a lot online but did not find a proper solution. I was trying to use Entity Framework Core with MySQL by using database-first scaffold method to mapping table model while always received this error when applied the command Unable to retrieve project metadata. Ensure it's an MSBuild-based .NET Core project. If you're using custom BaseIntermediateOutputPath or MSBuildProjectExtensionsPath values, Use the --msbuildprojectextensionspath option. This is the command I am using to scaffold the database model: Scaffold-DbContext "server=localhost;port=3306;user=root;password=1234

Can Entity Framework handle many to many relationship without an intersection object?

放肆的年华 提交于 2019-12-01 03:39:40
Using database first model: Let's say we have the classic tables Student , Course and StudentCourse (the latter obviously having FKs to Student and Course ). If you import this model to EF, you will get an object generated for each of them. The Student and Course classes will each have a collection of StudentCourses , from which you need to jump another relationship to get to the Course or Student , respectively. I would like to have the code generated in such a way that the underlying intersection table is invisible, i.e. Student has a collection of Courses , and Course has a collection of

How to name foreign keys with database first approach

情到浓时终转凉″ 提交于 2019-12-01 03:32:01
问题 Is there a way to change the naming convention with Entity Framework? Example : I have 2 tables Planification -------------- creator_id <fk> guest_id <fk> Profile -------------- profile_id <pk> creator_id and guest_id are both foreign keys for the profile_id by default, entity would generate a planification class like this public string guest_id { get; set; } public string creator_id { get; set; } public virtual Profile Profile { get; set; } public virtual Profile Profile1 { get; set; } I

Entity Framework many to many relationship with extra field (Database First)

家住魔仙堡 提交于 2019-12-01 03:26:26
问题 I have a program using Entity Framework (EF) Database First in the data access layer. I know that in order for EF to auto-generate the navigation properties of a many to many relationship, the mapping table needs to contain only a composite primary key: Project - ProjectId (PK) - Name ContentType - ContentTypeId (PK) - Name ProjectContentTypeMapping - ProjectId (PK) - ContentTypeId (PK) In this case everything works fine, and I can access Projects from ContentTypes and the other way around

Entity Framework 4.1 Database First does not add a primary key to the DbContext T4 generated class

倾然丶 夕夏残阳落幕 提交于 2019-12-01 01:25:56
问题 I am just getting started with Entity Framework 4.1, trying out the "database first" mode. When EF generates a Model class with the "ADO.Net DbContext Generator," shouldn't it identify the primary key for the class with a [Key] attribute? Without this, it appears incompatible with the T4 MVCScaffolding. Here are the details: Using the Entity Data Model Designer GUI, I have added a simple "country" table to the model from my existing database. The GUI correctly identifies a single integer

Can Entity Framework handle many to many relationship without an intersection object?

依然范特西╮ 提交于 2019-11-30 23:49:52
问题 Using database first model: Let's say we have the classic tables Student , Course and StudentCourse (the latter obviously having FKs to Student and Course ). If you import this model to EF, you will get an object generated for each of them. The Student and Course classes will each have a collection of StudentCourses , from which you need to jump another relationship to get to the Course or Student , respectively. I would like to have the code generated in such a way that the underlying

Binding ListBox with a model in MVC3

寵の児 提交于 2019-11-30 22:01:24
My model is public class SiteConfig { public SiteConfig() { } public int IdSiteConfig { get; set; } public string Name { get; set; } public byte[] SiteLogo { get; set; } public string Brands { get; set; } public string LinkColour { get; set; } public IEnumerable<SiteBrand> SiteBrands { get; set; } } and public class SiteBrand { public int Id { get; set; } public int SiteId { get; set; } public int BrandId { get; set; } public Brand Brand { get; set; } public SiteConfig SiteConfig { get; set; } } public class Brand { public int BrandId { get; set; } public string Name { get; set; } public

Generate Entity Framework model from Visual Studio database project

老子叫甜甜 提交于 2019-11-30 18:46:37
I'm using EF5 with a Database-First model. And a database project in visual Visual Studio to maintain the Sql Server database schema of an application. To update the EF model, I'm deploying the changes in a empty database... Is it possible to generate and update a EF model from a Visual Studio (2012) database project? UPDATE: Also generate it from a dacpac file is a not too bad option. Is it possible? UPDATE: In the MS Build 2014 Conference, the ADO.NET team suggested that the future releases from EF, like EF7, will only work with the Code First approach. Later, they clarify the name of the