Multi-to-One Handling in ASP.NET MVC 4

I wasn’t taught how to handle the many-in-one table in MVC 4, so please tell me about me.

I have a database that I created from my models, and it is very similar to the image below: enter image description here

However, in fact, working with CRUD operations is slightly different :(

So, I took my approach to how I handled the "normal" tables and tried to get it to work, but I couldn't.

here is my dal:

public class ArticleEntities : DbContext
{
    public DbSet<AgeGroup> AgeGroups { get; set; }
    public DbSet<Disabilities> Disabilitiess { get; set; }
    public DbSet<StrategyType> StrategyTypes { get; set; }
    public DbSet<Article> Articles { get; set; }
    public DbSet<UserProfile> Profiles { get; set; }
    public DbSet<DataToArticle> DataToArticles { get; set; }


    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
        modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
    }
}

What i want to do

- () AgeGroup, Disability StrategyType. , (, "" ), ( "-", "", "" ) . enter image description here

, AgeGroup, Disability, StrategyType . :

public virtual List<DataToArticle> AgeGroupToArticle { get; set; }

DataToArticle. DataToArticle:

    public virtual AgeGroup AgeGroup { get; set; }

    public virtual Disabilities Disabilities { get; set; }

    public virtual StrategyType StrategyType { get; set; }

, ,

ArticleController , . Linq, , , .

" " , .

, lol, .

+4
2

, , , , . , , , . , . . " ".

( , , , ), , . , , - " " .

, - , . , .

public ICollection<AgeGroup> AgeGroups { get; set; }
public ICollection<Disability> Disabilities { get; set; }
public ICollection<StrategyType> StrategyTypes { get; set; }

, , ( ), :

public class AgeGroup
{
     public int Id { get; set; }
     public int ArticleId { get; set; }
     public string AgeName { get; set; }

     public Article Article { get; set; }
}

Data model for article with multiple related age groups, disabilities, and strategy types

+3

EF Code First , MVC, , . asp.net/mvc.

0

Source: https://habr.com/ru/post/1529713/


All Articles