ef-code-first

EF Code First 6.1 Change ID from Int to Long

﹥>﹥吖頭↗ 提交于 2021-02-07 17:24:13
问题 I'm working on an application that is using ASP.Net MVC 4, C# and Entity Framework Code First. There is one model (Table) that is growing rather large and I'm worried that the Identity column will run out of values (Int32.MaxValue) in the next year or so. I'm looking for a way to change this identity from int to a long. In the past when I tried this, EF wouldn't let me do this unless if it dropped the table and recreated it. This is not an option since the site is already live and there is

“The number of properties in the Dependent and Principal Roles in a relationship constraint must be identical” issue in entity framework

 ̄綄美尐妖づ 提交于 2021-02-07 14:14:16
问题 I'm using .NET framework 4.0 with Entity Framework v6 code-first. I am creating 3 tables (" Indicadores ", " Campos " and " Codigos ") which use composite primary keys, but I am receiving an error when generating the model: One or more validation errors were detected during model generation: Codigos_Campos_Target_Codigos_Campos_Source: : The number of properties in the Dependent and Principal Roles in a relationship constraint must be identical. The code is here: public class Indicadores {

Specifying Foreign Key Entity Framework Code First, Fluent Api

不打扰是莪最后的温柔 提交于 2021-02-07 12:51:36
问题 I have a question about defining Foreign Key in EF Code First Fluent API. I have a scenario like this: Two class Person and Car. In my scenario Car can have assign Person or not (one or zero relationship). Code: public class Person { public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } } public class Car { public int Id { get; set; } public string Name { get; set; } public Person Person { get; set; } public int? PPPPP { get; set; } } class

Specifying Foreign Key Entity Framework Code First, Fluent Api

微笑、不失礼 提交于 2021-02-07 12:50:26
问题 I have a question about defining Foreign Key in EF Code First Fluent API. I have a scenario like this: Two class Person and Car. In my scenario Car can have assign Person or not (one or zero relationship). Code: public class Person { public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } } public class Car { public int Id { get; set; } public string Name { get; set; } public Person Person { get; set; } public int? PPPPP { get; set; } } class

EF Code First Update Database Encountered Error “There is already an object named 'Products' in the database”

南笙酒味 提交于 2021-02-07 10:30:17
问题 I'm using EF5 Code First in MVC4. There are tables where fields have decimal datatypes. I just wanted to update the precision of decimal originally from (18,2) to (18,4) . Please help. To achieve the goal I just modified the OnModelCreating something like this: protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity<DealerLevelDiscount>().Property(d =>d.Discount ).HasPrecision(18, 4); modelBuilder.Entity<DealerTransaction>().Property(d => d.ProductDiscount)

Representing a Junction Table in Entity Framework

血红的双手。 提交于 2021-02-07 10:09:52
问题 I am creating a schema where the following logic applies: A String can belong to multiple locations. Multiple Locations can have multiple String , or no String . The DateTime (As DateScraped ) at which the relationship between Location and String was formed must be recorded. Basically, I've mapped the relationship as a many-to-many relationship using a junction table like so: In mapping the chart in Code First EF6 (Using SQLite), I have the following objects: public class Location { [Key,

Representing a Junction Table in Entity Framework

你说的曾经没有我的故事 提交于 2021-02-07 10:09:32
问题 I am creating a schema where the following logic applies: A String can belong to multiple locations. Multiple Locations can have multiple String , or no String . The DateTime (As DateScraped ) at which the relationship between Location and String was formed must be recorded. Basically, I've mapped the relationship as a many-to-many relationship using a junction table like so: In mapping the chart in Code First EF6 (Using SQLite), I have the following objects: public class Location { [Key,

Representing a Junction Table in Entity Framework

泄露秘密 提交于 2021-02-07 10:09:28
问题 I am creating a schema where the following logic applies: A String can belong to multiple locations. Multiple Locations can have multiple String , or no String . The DateTime (As DateScraped ) at which the relationship between Location and String was formed must be recorded. Basically, I've mapped the relationship as a many-to-many relationship using a junction table like so: In mapping the chart in Code First EF6 (Using SQLite), I have the following objects: public class Location { [Key,

what is advantage of CodeFirst over Database First?

▼魔方 西西 提交于 2021-02-07 02:46:25
问题 I was watching some videos and tutorials for EF 4.1, and I do not understand any benefit of CodeFirst (except some if DB is very small 3-4 tables and I am lazy for creating DB first). Mostly, the best approach so far is to create Database in some sort of Database editor, which is sure faster then editing in the Entity Model and EF picks up every relationships and creates associations correctly. I know there are challenges in naming convention etc, but I feel its very confusing to manage Code

Entity Framework Code First: Configuration.cs seed or custom initializer

ぃ、小莉子 提交于 2021-02-06 20:47:24
问题 I am working with the the Code First style of the Entity Framework for my first time. I want to set up some default data. The first approach I came across involved creating a custom initializer. I was headed this route but noticed after setting up migrations that it came with the Configuration.cs that already overrides the seed method just like the custom initializer. internal sealed class Configuration : DbMigrationsConfiguration<Toolkit.Model.ToolkitContext> { public Configuration() {