实体框架:编辑视图模型 [英] Entity framework: edit view model

查看:76
本文介绍了实体框架:编辑视图模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个类(实体)和一个视图模型。我想编辑我的视图模型并保存到每个实体。



首先:模型有问题吗?

第二:如何将myViewModel数据检索到编辑视图?我找不到适合我模特的编辑示例。



我尝试过的事情:



我有以下课程:SALES,PRICE和COUNTRIES,SALES为其他课程提供一个>许多。



  public   partial   class  SALES 
{
[key]
public int id_sales {< span class =code-keyword> get ; set ; }
public DateTime offer_dateC { get ; set ; }
public int comnamC { get ; set ; }
public string sales_contactC { get ; set ; }
public string prod_name_pharma_formC { get ; set ; }
public virtual ICollection< PRICE>价格{获取; set ; }
public virtual ICollection< COUNTRIES>国家{获取; set ;
}

public partial PRICE
{
[Key]
public int id_price { get ; set ; }
public decimal priceC { get ; set ; }
public string strengthC { get ; set ; }
public string quantity { get ; set ; }
public string currency { get ; set ; }
public virtual SALES SALES { get < /跨度>; set ; }
}

public partial class COUNTRIES
{
[Key]
public int id_country { get ; set ; }
public string countryC { get ; set ; }
public string coountry_name { get ; set ; }
public virtual SALES SALES { get < /跨度>; set ; }
}



ModelView是:

  public   class  myViewModel 
{
[Key]
public int id_offers { get ; set ; }

public DateTime offer_dateC { get ; set ; }
public int comnamC { get ; set ; }
public string sales_contactC { get ; set ; }
public string prod_name_pharma_formC { get ; set ; }
public 列表< decimal> priceC { get ; set ; }
public string strengthC { get ; set ; }
public string quantity { get ; set ; }
public string currency { get ; set ; }
public List< string> countryC { get ; set ; }
}

解决方案

查看软件包管理器控制台命令 update-database

I have several classes (entities) and a View Model. I want to edit my view model and save into each entity.

First: Is there something wrong with the model?
Second: How to retreive myViewModel data into the edit view? I couldn't find an Edit example suitable for my model.

What I have tried:

I have the following classes: SALES, PRICE and COUNTRIES where SALES gives one->many to the other classes.

     public partial class SALES
      {
        [key]
        public int id_sales { get; set; }
        public DateTime offer_dateC { get; set; }
        public int comnamC { get; set; }
        public string sales_contactC { get; set; }
        public string prod_name_pharma_formC { get; set; }
        public virtual ICollection<PRICE> PRICE { get; set; }
        public virtual ICollection<COUNTRIES> COUNTRIES { get; set; 
      }

public partial class PRICE
    {
        [Key]
        public int id_price { get; set; }
        public decimal priceC { get; set; }
        public string strengthC { get; set; }
        public string quantity { get; set; }
        public string currency { get; set; }
        public virtual SALES SALES { get; set; }
    }

public partial class COUNTRIES
    {
        [Key]
        public int id_country { get; set; }
        public string countryC { get; set; }
        public string coountry_name { get; set; }
        public virtual SALES SALES { get; set; }
    }


And the ModelView is:

public class myViewModel
    {
      [Key]
      public int id_offers { get; set; }

      public DateTime offer_dateC { get; set; }
      public int comnamC { get; set; }
      public string sales_contactC { get; set; }
      public string prod_name_pharma_formC { get; set; }
      public List<decimal> priceC { get; set; }
      public string strengthC { get; set; }
      public string quantity { get; set; }
      public string currency { get; set; }
      public List<string> countryC { get; set; }
    }

解决方案

look into the package manager console command update-database


这篇关于实体框架:编辑视图模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆