entity-framework-6

Set DatabaseInitializerForType in config file for Custom Initializer to fire

99封情书 提交于 2019-12-11 03:17:22
问题 So I either get errors firing or nothing happens. I know that I have custom Entity Framework Initializer like this: using System; using System.Collections.Generic; using System.Data.Entity; using System.Linq; using System.Text; using System.Threading.Tasks; namespace EasyEntity { public class EasyInitializer : DropCreateDatabaseAlways<EasyContext> { protected override void Seed(EasyContext context) { List<Person> persons = new List<Person> { new Person { FirstName = "Waz", LastName = "Amattau

Database Initialization in Entity Framework Code First

烂漫一生 提交于 2019-12-11 03:12:39
问题 I'm learning about EF Code First. I've read Database Initialization Strategies in Code-First and Understanding Database Initializers in Entity Framework Code First articles. But I'm still confused, where should be the data before initialization? Those articles didn't mention about that and I think it's pretty important. I'm building a football application, so while initializing app I'd like to insert every team and player name into database (every in the Europe from best leagues - so quite a

EF code-first: Sequence contains more than one matching element

你离开我真会死。 提交于 2019-12-11 02:57:35
问题 I'm using EF6 code-first, and have a User class that needs to have incoming and outgoing connections to other users. A connection also has properties, so I also have a Connections class. public class User { public int ID { get; set; } // Other properties removed here to keep it simple [InverseProperty("SourceUser")] public virtual ICollection<Connection> OutgoingConnections { get; set; } [InverseProperty("DestUser")] public virtual ICollection<Connection> IncomingConnections { get; set; } }

How to update multiple many to many relationship and check for concurrency exceptions?

余生长醉 提交于 2019-12-11 02:54:24
问题 I was wondering how could I update an entity with multiple many to many relationships. So if I had a car model with many connectors, inputvoltages, lenstypes and lightcolors. I want the user to be able to update all selections on one page and so when they submit the page all connectors, lights, etc are added or removed from the car. I was wondering if I should use a ViewModel and have each entity on the ViewModel or use the view-bag and pass a list of items. For when the user saves if someone

Entity Framework duplicates lookup values when assigned to nested list member

好久不见. 提交于 2019-12-11 02:48:04
问题 This solution involves three entities, Client , Competency and WeaponType . A Client instance can have zero-or-more Competency instances within a List<Competency> member. A Competency instance can have one-or-more WeaponType instances within a List<WeaponType> member. ( WeaponType is our lookup member) Before updating the DbContext, a new List object is assigned to the client. This represents the full updated list of competencies for the client, where old competencies might have been removed

How to use Linq to join entity tables with a cross-reference table

泪湿孤枕 提交于 2019-12-11 02:34:39
问题 Let me preface this by saying I'm relatively new to Linq, but I seem to have grasped most of it pretty quickly. But this problem has me stumped. I've searched and searched to no avail. I am using code-first and have created have 2 models, "Items" and "Keywords". They have a many-to-many relationship on them. My entity models look like this: public class MyContext : DbContext { public MyContext() : base("name=DefaultDatabase") { } protected override void OnModelCreating(System.Data.Entity

Entity Framework 6.2 copy many to many from one DbContext to another DbContext

帅比萌擦擦* 提交于 2019-12-11 02:20:50
问题 When working with a network database such as MySQL, the DbContext should be short lived, but according to https://www.entityframeworktutorial.net/EntityFramework4.3/persistence-in-entity-framework.aspx the DbContext can be long lived when working with a local database, such as SQLite. My app is using a long lived DbContext to work with SQLite on HDD and I want to copy many-to-many entities to another DbContext for the same type of SQLite database on USB. I am using the Code-First approach.

How to efficiently set default entity values in Entity Framework 6, Database First

北城余情 提交于 2019-12-11 02:14:51
问题 I am new to Entity Framework and have only worked with database first development so far. I have been reading Entity Framework 2E which focuses on EF4. The generated classes in EF4 had no parameterless constructor so I was able to define partial classes and initialize entity properties in the parameterless constructors I defined there. The other options were to edit the EDMX directly and set the StoreGeneratedPattern attribute of a property to Computed or set the Default Value attribute of

Error: Multiple object sets per type are not supported

浪子不回头ぞ 提交于 2019-12-11 02:03:56
问题 Here is details of the error: There was an error running the selected code generator: 'Unable to retrive metadata for 'Models.ApplicationUser'. Multiple object sets per type are not supported. The objects sets 'ApplicationUsers' and 'Users' can both contain instances of type 'Models.ApplicationUser'. I am getting this while scaffolding a view in MVC project. I got the same error if i try to scafford a controller. I have seen a few of this error on SO but it seems those don't apply to my case.

How create composite foreign key to table with composite primary key

对着背影说爱祢 提交于 2019-12-11 01:48:30
问题 I have two tables with composite primary keys: public class Event { [Key] [Column(Order = 1)] public string ID1 { get; set; } [Key] [Column(Order = 2)] public int ID2 { get; set; } public DateTime EventDate { get; set; } public string DocID1 { get; set; } public int DocID2 { get; set; } } public class EventDocument { [Key] [Column(Order = 1)] public string ID1 { get; set; } [Key] [Column(Order = 2)] public int ID2 { get; set; } public string Name { get; set; } public string SurName { get; set