entity-framework

Entity Framework multiple references to same table

柔情痞子 提交于 2021-02-07 18:30:09
问题 I'm having trouble creating my database with EF code-first. I have an entity Player and an entity friedship. Each friendship references two players. One of the players is the sender, the other one is the receiver of the friendship. This are my entities: Player.cs public class Player { public int PlayerId { get; set; } [Required] public string Name { get; set; } [Required] public string Email { get; set; } [InverseProperty("Receiver")] public virtual List<Friendship> FriendshipsIncoming { get;

Unable to determine a composite foreign key ordering for foreign key

我是研究僧i 提交于 2021-02-07 17:28:25
问题 Person is the user model that includes all users. The change model includes the EngineerId and the ManagerId, both are Person IDs. Why am I getting this error? Unable to determine a composite foreign key ordering for foreign key on type ProjectName.Models.Change. When using the ForeignKey data annotation on composite foreign key properties ensure order is specified by using the Column data annotation or the fluent API. public class Change { [Key] public int ChangeId { get; set; } [Required

EF Code First 6.1 Change ID from Int to Long

﹥>﹥吖頭↗ 提交于 2021-02-07 17:24:33
问题 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

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

How many DbContext subclasses should I have, in relation to my models?

孤人 提交于 2021-02-07 14:44:32
问题 I'm learning ASP.NET MVC and I'm having some questions that the tutorials I've read until now haven't explored in a way that covers me. I've tried searching, but I didn't see any questions asking this. Still, please forgive me if I have missed an existing ones. If I have a single ASP.NET MVC application that has a number of models (some of which related and some unrelated with each other), how many DbContext subclasses should I create, if I want to use one connection string and one database

How many DbContext subclasses should I have, in relation to my models?

二次信任 提交于 2021-02-07 14:42:18
问题 I'm learning ASP.NET MVC and I'm having some questions that the tutorials I've read until now haven't explored in a way that covers me. I've tried searching, but I didn't see any questions asking this. Still, please forgive me if I have missed an existing ones. If I have a single ASP.NET MVC application that has a number of models (some of which related and some unrelated with each other), how many DbContext subclasses should I create, if I want to use one connection string and one database

LINQ: The cast to value type 'System.Int32' failed because the materialized value is null

微笑、不失礼 提交于 2021-02-07 14:25:59
问题 I'm getting the following error when executing a LINQ query on my database: The cast to value type 'System.Int32' failed because the materialized value is null. I believe it's because one of the columns is returning a null. Here is my LINQ command: var facts = (from b in Program.db.ProductBrands join bm in Program.db.BrandManufacturers on b.ProductBrandID equals bm.ProductBrandID join c in Program.db.Companies on bm.ProductManufacturerID equals c.CompanyID join s in Program.db.AnimalSources

LINQ: The cast to value type 'System.Int32' failed because the materialized value is null

淺唱寂寞╮ 提交于 2021-02-07 14:24:20
问题 I'm getting the following error when executing a LINQ query on my database: The cast to value type 'System.Int32' failed because the materialized value is null. I believe it's because one of the columns is returning a null. Here is my LINQ command: var facts = (from b in Program.db.ProductBrands join bm in Program.db.BrandManufacturers on b.ProductBrandID equals bm.ProductBrandID join c in Program.db.Companies on bm.ProductManufacturerID equals c.CompanyID join s in Program.db.AnimalSources

“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 {

how to change isolation level?

时光怂恿深爱的人放手 提交于 2021-02-07 14:13:57
问题 I am using EF 4.0, and I would like to use the isolation level serializable , because in a transaction I would like to block a register when is read. Well, in SQL Server I try to change the isolation level with this command: SET TRANSACTION ISOLATION LEVEL SERIALIZABLE; And in C# I use this code to try to block the register: using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.Serializable })) {