ef-code-first

EF 4.1 Code First: Many to Many

邮差的信 提交于 2019-12-24 16:58:41
问题 I have 2 entities, let's say A and B. Relation between them is many-to-many so I have another entity, let's say C. Columns for table A: -Id (PK) -> Type int generated by database -PropertyA1 -PropertyA2 -PropertyA3 Columns for table B: -Id (PK) -> Type int generated by database -Description Columns for table C (For this table I am not sure if it is better to add an extra column Id generated by database as previous tables): -IdA (PK and also foreign key to entity A) -IdB (PK and also foreign

Entity Framework 6.12 cascade Delete ( one to many relationship)

依然范特西╮ 提交于 2019-12-24 16:15:57
问题 i have two table parent(id p_key,name) and child(addresid,city, id ForeignKey) table have one to many relationship , so if i am deleting any recording from parent table then all related record should be deleted from child table i am using entity framework code first approach 回答1: Add this to your DB Context : protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity<parent>() .HasOptional(c => c.child) .WithOptionalDependent() .WillCascadeOnDelete(true); }

Move simple membership profider functionality to class library project

与世无争的帅哥 提交于 2019-12-24 13:48:09
问题 I'm trying to move my DbSet 's to a class library project that is going to be used for database operations. I've been following this tutorial to a Code First / SimpleMembershipProfider project. I've already got the database filled with new tables etc, via the class lib project. But i am missing the webpages_ tables you can see on this image. This is my datacontext class: public class DataContext : DbContext { public DataContext() : base("DefaultConnection") { } public DbSet<Orders> Orders {

Can you customise foreign key names in self referencing entities in entity framework?

假装没事ソ 提交于 2019-12-24 12:53:45
问题 Some of the entities in my application have 4 audit properties on them: public virtual DateTime WhenAdded { get; set; } public virtual DateTime? WhenUpdated { get; set; } public virtual User AddedBy { get; set; } public virtual User UpdatedBy { get; set; } I am using a code first approach and have the following extension method to map the user properties: public static void MapAuditFields<T>(this EntityTypeConfiguration<T> configuration) where T : class, IAuditable { configuration.HasOptional

How do I specify which field should be displayed with MVC Scaffolding

六眼飞鱼酱① 提交于 2019-12-24 12:14:12
问题 I am creating an MVC4 application using EF Code First database. I am working with some foreign key declarations. I wish to use define the field to display in the dropdown in the scaffolding in the model declarations. For instance: My simplified model declaration is as follows: public class Contact { public int ID { get; set; } public string Prefix { get; set; } public string First { get; set; } public string Middle { get; set; } public string Last { get; set; } public string FullName { get {

Entity Framework Code First model separation from domain

丶灬走出姿态 提交于 2019-12-24 11:59:24
问题 Entity Framework Code First best practice question? Hi All I am using EF codeFirst 6 on an NTier app. I have found that poco object that I am using to map to EF are really EntityFramework specific. Let me give you an example If I want to add a property that is not related to EF in the object ,EF does not like it. I Read you can put the "NotMapped" attribute however it start making this object difficult to maintain . Also there might be developers that are not familiar with EF and that will

How to create user defined functions using code first in ABP?

我的未来我决定 提交于 2019-12-24 11:29:49
问题 I want to create some user-defined functions using code first approach in abp framework. I have created stored procedures xyz by adding xyz.sql inside EntityFrameworkCore\Migrations\Stored Procedures folder, But not able to find a way to create a function, please help. 来源: https://stackoverflow.com/questions/48262776/how-to-create-user-defined-functions-using-code-first-in-abp

How to add existing collection of entities to existing entity without pulling first pulling existing entities from database using code-first framework

。_饼干妹妹 提交于 2019-12-24 10:39:44
问题 I'm trying to attach two existing and one new bid bid to an existing auction, but am unable to do so without first pulling the product from the database. This code works, but how would I go about just providing the bid id's for the existing bids and then save the auction using (var db = new DataContext()) //find existing auction var auction = db.Auctions.Find(1); var bid1 = db.Bids.Find(1); var bid2 = db.Bids.Find(2); var bid3 = new Bid() { //New Bid }; //existing auction.Bids.Add(bid1); /

“The underlying provider failed on Open” Error when using EF5 Code First with Unity IoC in Azure Worker Role against SQL Azure

回眸只為那壹抹淺笑 提交于 2019-12-24 09:36:10
问题 I am using Entity Framework 5 Code First, I use the repository and unit of work pattern, and have my domain models, repositories, and service layer working fine within an MVC app running in a Windows Azure cloud service. I'm using Unity for IoC and inject repositories, controllers, and service classes as required, and use a per-request lifetime. It has been working great. However, when I use the same code/class libraries for the domain, repository, and the EF5 DbContext, in an Azure Worker

Populate a list property from delimited string

左心房为你撑大大i 提交于 2019-12-24 08:49:11
问题 This is kind of a simple application but I'm a bit new to ASP.NET MVC so I'm having a bit of trouble wrapping my head around how to accomplish this because the What I have are two classes: public class BugAssignment { public int BugAssignmentID { get; set; } public int BugNumber { get; set; } public int UserID { get; set; } public virtual User User { get; set; } } public class BugAssignmentList { public int BugAssignmentListID { get; set; } public string Name { get; set; } public List