ef-code-first

EF code-first many-to-many with additional data

戏子无情 提交于 2019-12-17 16:43:25
问题 I have these tables: CREATE TABLE [EDR_SECURITY].[Person]( [ixPerson] [bigint] IDENTITY(1,1) NOT NULL, [sName] [nvarchar](200) NOT NULL, ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] CREATE TABLE [EDR_SECURITY].[SecurityGroup]( [ixSecurityGroup] [bigint] IDENTITY(1,1) NOT NULL, [sName] [nvarchar](200) NOT NULL, [sDescription] [nvarchar](400) NULL, ) ON [PRIMARY] CREATE TABLE [EDR_SECURITY].[PersonSecurityGroupDefinition]( [ixPerson] [bigint] NOT NULL, [ixSecurityGroup] [bigint] NOT NULL, [fPrivilege]

Entity Framework Code First Migrations: Set Primary Key Value

前提是你 提交于 2019-12-17 16:30:13
问题 I have a table that stores some extra data for some rows of a table like: public class QuoteExtra { [Key] public int QuoteId { get; set; } // More fields here } I'd like to be able to add rows to this table where I explicitly set the PK. If I simply leave it as above, setting a value and submitting the row causes the value to be discarded and replaced with the auto-generated value from the database (and the column is defined as an Identity column in the actual schema). This appears to be the

EF4.1 Code First: Stored Procedure with output parameter

徘徊边缘 提交于 2019-12-17 15:52:06
问题 I use Entity Framework 4.1 Code First. I want to call a stored procedure that has an output parameter and retrieve the value of that output parameter in addition to the strongly typed result set. Its a search function with a signature like this public IEnumerable<MyType> Search(int maxRows, out int totalRows, string searchTerm) { ... } I found lots of hints to "Function Imports" but that is not compatible with Code First. I can call stored procedures using Database.SqlQuery(...) but that does

Mapping a foreign key with a custom column name

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-17 15:47:14
问题 I'm using Entity Framework 4.3 code-first with Oracle. I'm getting the following error: System.InvalidOperationException : The ForeignKeyAttribute on property 'WidgetSequence' on type 'WidgetDistributor.WidgetEntity' is not valid. The foreign key name 'WIDGETSEQUENCE_ID' was not found on the dependent type 'WidgetDistributor.WidgetEntity'. The Name value should be a comma separated list of foreign key property names. My entities are like this: [Table("WIDGETENTITIES")] public class

The relationship could not be changed because one or more of the foreign-key properties is non nullable

倾然丶 夕夏残阳落幕 提交于 2019-12-17 15:42:51
问题 I get following error during update with EF: The operation failed: The relationship could not be changed because one or more of the foreign-key properties is non-nullable. When a change is made to a relationship, the related foreign-key property is set to a null value. If the foreign-key does not support null values, a new relationship must be defined, the foreign-key property must be assigned another non-null value, or the unrelated object must be deleted. Is there any general way to find

The relationship could not be changed because one or more of the foreign-key properties is non nullable

拜拜、爱过 提交于 2019-12-17 15:42:29
问题 I get following error during update with EF: The operation failed: The relationship could not be changed because one or more of the foreign-key properties is non-nullable. When a change is made to a relationship, the related foreign-key property is set to a null value. If the foreign-key does not support null values, a new relationship must be defined, the foreign-key property must be assigned another non-null value, or the unrelated object must be deleted. Is there any general way to find

Linq when using GroupBy, Include is not working

故事扮演 提交于 2019-12-17 15:39:45
问题 include matchparticipants is not working. It always says Null when I debug. But when I put the GroupBy in comment it works fine. I am using Entity framework 4.3.1 with code-first. Entities: public class Match { [ScaffoldColumn(false)] public int MatchId { get; set; } [Required(ErrorMessage = "Matchtype is a required field")] public int Scheme { get; set; } [Required] [DefaultValue(false)] public bool Finished { get; set; } public int Round { get; set; } // Relations [Required] public Category

Linq when using GroupBy, Include is not working

陌路散爱 提交于 2019-12-17 15:39:00
问题 include matchparticipants is not working. It always says Null when I debug. But when I put the GroupBy in comment it works fine. I am using Entity framework 4.3.1 with code-first. Entities: public class Match { [ScaffoldColumn(false)] public int MatchId { get; set; } [Required(ErrorMessage = "Matchtype is a required field")] public int Scheme { get; set; } [Required] [DefaultValue(false)] public bool Finished { get; set; } public int Round { get; set; } // Relations [Required] public Category

Entity Framework DbContext SaveChanges() OriginalValue Incorrect

匆匆过客 提交于 2019-12-17 14:03:46
问题 I am trying to implement an AuditLog using EF 4.1, by overriding the SaveChanges() method as discussed in the following places: http://jmdority.wordpress.com/2011/07/20/using-entity-framework-4-1-dbcontext-change-tracking-for-audit-logging/ Entity Framework 4.1 DbContext Override SaveChanges to Audit Property Change I am having problems with the "modified" entries though. Whenever I attempt to get at the OriginalValue of the property in question, it always has the same value as it does in the

A dependent property in a ReferentialConstraint is mapped to a store-generated column error on 1-to-1 relationship

我是研究僧i 提交于 2019-12-17 13:57:50
问题 In EntityFramework code first models, there exists a 1:1 relationship: public class Child1 { [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } public string Name { get; set; } public Child2 Child2 { get; set; } } public class Child2 { [DatabaseGenerated(DatabaseGeneratedOption.Identity)] [ForeignKey("Child1")] public int Id { get; set; } public string Name { get; set; } public Child1 Child1 { get; set; } } When I tried to insert some data to the database, it