entity-framework

Problems creating a Foreign-Key relationship on Entity Framework

强颜欢笑 提交于 2020-01-10 08:10:52
问题 i'm having trouble configuring a foreign key relationship in my Entity Framework fluent Api: Here is the head of the report: public class Testata { public Testata() { Details = new List<Dettaglio>(); } public virtual int IDTEST { get; set; } public virtual string Value { get; set; } public virtual int IDDETAIL { get; set; } public virtual string IDTESTALT { get; set; } public virtual byte[] BLOB { get; set; } public virtual IList<Dettaglio> Details { get; set; } } This is the report's detail

Problems creating a Foreign-Key relationship on Entity Framework

六眼飞鱼酱① 提交于 2020-01-10 08:10:07
问题 i'm having trouble configuring a foreign key relationship in my Entity Framework fluent Api: Here is the head of the report: public class Testata { public Testata() { Details = new List<Dettaglio>(); } public virtual int IDTEST { get; set; } public virtual string Value { get; set; } public virtual int IDDETAIL { get; set; } public virtual string IDTESTALT { get; set; } public virtual byte[] BLOB { get; set; } public virtual IList<Dettaglio> Details { get; set; } } This is the report's detail

Use the ColumnAttribute or the HasKey method to specify an order for composite primary keys

大憨熊 提交于 2020-01-10 07:52:21
问题 I'm trying to use composite primary key on 2 objects with parent-child relationship. Whenever I try to create a new migration, I get an error: Unable to determine composite primary key ordering for type 'Models.UserProjectRole'. Use the ColumnAttribute or the HasKey method to specify an order for composite primary keys. As per error suggests, I do add annotation Column (Order = X) but the error still there and does not go away, unless I leave only one field with Key annotation. Here is my

Transient Fault Handling with SQL Azure using Entity Framework

淺唱寂寞╮ 提交于 2020-01-10 07:43:09
问题 I currently use SQL Azure and Entity SQL in my application. e.g. Entities model = new Entities(); db_Item item = model.db_Item.First(); Now I want to use the Transient Fault Handling out of the Enterprise Library but there are no examples or solutions that I can find that would allow me to do something like override the Entities class, so I don't have to update my code in hundreds of places. Could someone please provide more information on how this could be done? 回答1: Going through what I

DbUpdateConcurrencyException using Entity Framework 6 with MySql

*爱你&永不变心* 提交于 2020-01-10 05:33:05
问题 I'm having trouble with concurrency checks using EF6 and MySQL. The problem I'm having is that I get a concurrency exception thrown when I try to save data to the database. If you examine the sql that is output to the console it tries to query the concurrency field from the database using the old value in the where clause. Because this field has been updated by the database. Environment: Windows 7 64 bit Visual Studio 2013 Nuget packages installed: EF 6.0.1 MySql.ConnectorNET.Data 6.8.3.2

The instance of entity type 'Product' cannot be tracked because another instance with the same key value is already being tracked

醉酒当歌 提交于 2020-01-10 05:11:14
问题 I made a test with code below to update the Product : var existing = await _productRepository.FirstOrDefaultAsync(c => c.Id == input.Id); if (existing == null) throw new UserFriendlyException(L("ProductNotExist")); var updatedEntity = ObjectMapper.Map<Product>(input); var entity = await _productRepository.UpdateAsync(updatedEntity); But it throws an exception: Mvc.ExceptionHandling.AbpExceptionFilter - The instance of entity type 'Product' cannot be tracked because another instance with the

How to change size of existing column using Entity Framework 6 Code First

喜夏-厌秋 提交于 2020-01-10 04:40:07
问题 I have a POCO Plant that is mapped to a table dbo.Plant in my DB (SQL SERVER 2014). Some of the columns in the database has the data types nvarchar(max) NULL. I am trying to change the data type via EntityTypeConfiguration using the following code: Property(x => x.PCode).HasMaxLength(25); But, when adding the migration (add-migration name), the resulting Up()-method will not contain any changes for this column. However, if I also make it required like this: Property(x => x.PCode).HasMaxLength

Lazy loading properties after an insert

那年仲夏 提交于 2020-01-10 03:07:46
问题 I have a parent and child object. If I do the following Child c = new Child(); c.ParentID = parentID; context.Child.Add(c); context.SaveChanges(); int i = c.Parent.ParentID; // throws an exception b/c Parent is null Why is this doing this? If I get a new context (after saving), I can see Parent just fine. 回答1: I guess you are working with lazy loading enabled. If you want that the navigation property gets populated after adding the object with the foreign key property to the context you must

Querying against DbContext.Set(TypeVariable) in Entity Framework

假装没事ソ 提交于 2020-01-10 03:06:46
问题 I'm re-factoring an application to invert some dependencies. Part of the original code uses DbContext.Set<MyEntityType>() to obtain the set to query against. With the inversion, the MyEntityType is no longer explicitly known to the code using DbContext.Set<MyEntityType>() , so now I'm using DbContext.Set(TypeVariable) instead. The re-factoring works to the extent that the correct DbSet is being returned. However, the type DbContext.Set(TypeVariable).Local is IList (contained type unknown)

Querying against DbContext.Set(TypeVariable) in Entity Framework

我们两清 提交于 2020-01-10 03:06:06
问题 I'm re-factoring an application to invert some dependencies. Part of the original code uses DbContext.Set<MyEntityType>() to obtain the set to query against. With the inversion, the MyEntityType is no longer explicitly known to the code using DbContext.Set<MyEntityType>() , so now I'm using DbContext.Set(TypeVariable) instead. The re-factoring works to the extent that the correct DbSet is being returned. However, the type DbContext.Set(TypeVariable).Local is IList (contained type unknown)