code-first

NullReferenceException in EF 5-6.1.1 with two navigation properties to the same type

眉间皱痕 提交于 2020-01-23 07:53:27
问题 I'd like to start with that I have a workaround for this issue - but I spent a few hours today figuring out the cause of the exception, so I'd thought I'd share Given two entities in the domain: public class User { public int Id { get; set; } public string Name { get; set; } } public class Ticket { public int Id { get; set; } public string Name { get; set; } public virtual User Owner { get; set; } public int? LockedByUserId { get; set; } public virtual User LockedByUser { get; set; }

More than one migrations configuration type was found in the assembly ''. Specify the name of the one to use. On add-migration

好久不见. 提交于 2020-01-23 05:34:24
问题 In Package Manager Console, I'm trying to update my database. When I enter this command : add-migration Migration1 And I get this : More than one migrations configuration type was found in the assembly 'MyProject.POCO'. Specify the name of the one to use. I googled the error and I get this : add-migration InitialBSchema -IgnoreChanges -ConfigurationTypeName ConfigurationB -ProjectName ProjectContextIsInIfNotMainOne -StartupProjectName NameOfMainProject -ConnectionStringName ContextB But I don

Entity Framework loading child collection with sort order

北战南征 提交于 2020-01-18 07:21:28
问题 I have two tables a parent and a child table. The child table has a column sortorder (a numeric value). Because of the missing support of the EF to persist a IList inclusive the sort order without exposing the sortorder (see: Entity Framework persisting child collection sort order) my child class has also a property SortOrder, so that i can store the children with the sort order. In contrast to the autor of the referenced question i try to load the children always sorted. So if i load a

Entity Framework loading child collection with sort order

扶醉桌前 提交于 2020-01-18 07:20:21
问题 I have two tables a parent and a child table. The child table has a column sortorder (a numeric value). Because of the missing support of the EF to persist a IList inclusive the sort order without exposing the sortorder (see: Entity Framework persisting child collection sort order) my child class has also a property SortOrder, so that i can store the children with the sort order. In contrast to the autor of the referenced question i try to load the children always sorted. So if i load a

Can not create my DbContext in a Unit test

梦想的初衷 提交于 2020-01-17 08:26:24
问题 When I create my TLPContext in a unit test I get an exception at the bottom of this page. I did this in the unit test: DbContext context = new TLPContext(); context.Database.CreateIfNotExists(); Is this not the correct approach? What is wrong with my connection string / provider ? I have followed this: http://www.thereforesystems.com/turn-on-msdtc-windows-7/ but it did not help after a reboot. Thats my app.config file in my unit test project: <?xml version="1.0" encoding="utf-8"?>

EntityFramework 4.3.1 Code First Navigation Property Mapping and Visibility

笑着哭i 提交于 2020-01-17 04:06:27
问题 This is a long introduction for a short question, sorry!! I'm working with EF 4.3.1 Code First and I've got the following model public class Action { protected Action() { } public virtual int ActionID { get; protected set; } [Required] [StringLength(DataValidationConstants.NameLength)] public virtual string Name {get; set;} [StringLength(DataValidationConstants.DescriptionLength)] public virtual string Description { get; set; } public virtual ICollection<Role> Roles { get; set; } public

Implement custom “ValidateUser” in MembershipProvider

送分小仙女□ 提交于 2020-01-16 05:11:46
问题 I am implementing a custom MembershipProvider and I am trying to get the ValidateUser method to validate against my Profiles table in SQL Server. This table has columns called UserName and Password . public override bool ValidateUser(string username, string password) { ??? what to do here??? } FYI, I am using MVC3 & EF 4.1 Code First. Thanks Paul 回答1: If you're using EF 4.1, you will have some kind of a DbContext object that contains the DbSet for your Profiles table - right? So in that case,

Entity Framework 6 + Code First + Oracle 11g

▼魔方 西西 提交于 2020-01-16 00:49:12
问题 Is there any way to create 100% the Oracle11g database using EF Code First? And how to trace the Oracle query in SaveChanges? 回答1: You can use third party to have a code first solution with oracle and ef 6 one of this providers is DevArt you can read more about the support here Ef6 in devart And about the log you can enable log in ef6 as is explained here http://msdn.microsoft.com/pt-br/data/dn469464 回答2: Try oracle odac 12c release 3, but only support EF6 code first. 回答3: I know its 2015 and

EF Code First Foreign Key's

时间秒杀一切 提交于 2020-01-15 05:01:35
问题 I am working with the EF Code First library trying to work on an appointment scheduling app. The model's I have are going to be a Client, Appointment, and AppointmentType... Basically each Client can have a set of Appointments, and each Appointment can have a single AppointmentType... The code is as follows: public class Client { [ScaffoldColumn(false)] public int ClientID { get; set; } [Required] public string FirstName { get; set; } [Required] public string LastName { get; set; }

Specify a cascading delete for parent / child relationships?

房东的猫 提交于 2020-01-14 19:23:28
问题 Model: public class MenuItem { public Guid Id {get;set;} public virtual Guid? ParentMenuItemId {get;set;} public virtual MenuItem ParentMenuItem {get;set;} public virtual ICollection<MenuItem> ChildMenuItems {get;set;} } current mapping: HasOptional(m => m.ParentMenuItem).WithMany(p => p.ChildMenuItems).HasForeignKey(m => m.ParentMenuItemId); I tried adding the WillCascadeOnDelete(true) , but I got an error. How should I update my mapping to allow for cascading deletes? So, If I delete a