C# 如何使用实体框架创建复杂类型?(包括或部分视图)

C# 如何使用实体框架创建复杂类型?(包括或部分视图),c#,asp.net-mvc,C#,Asp.net Mvc,我在Mvc的entityfreamwork上工作了很长时间 创建复杂类型时,我使用entityframework包含方法,还是通过向局部视图发送id来破坏模型 我使用局部视图 <div class="sidebar-item product-info"> <h4>İlan Durumu</h4> <hr class="line-separator"> <!-- INFOR

我在Mvc的entityfreamwork上工作了很长时间

创建复杂类型时,我使用entityframework包含方法,还是通过向局部视图发送id来破坏模型

我使用局部视图

<div class="sidebar-item product-info">
            <h4>İlan Durumu</h4>
            <hr class="line-separator">
            <!-- INFORMATION LAYOUT -->
            <div class="information-layout">
                <!-- INFORMATION LAYOUT ITEM -->
                <div class="information-layout-item">
                    <p class="text-header">Başlangıç Fiyatı:</p>
                    <p>@string.Format("{0:N0}", Model.MaxPrice) ₺</p>
                </div>
                <!-- /INFORMATION LAYOUT ITEM -->
                @Html.Action("AuctionBestOffer", "Offer", new { auction = Model.Id })
                <!-- INFORMATION LAYOUT ITEM -->
                <div class="information-layout-item">
                    <p class="text-header">Favorilere Ekle:</p>
                    @Html.Action("UserHasFavoriteAuctionDetail", "FavoriteAuction", new { auction = Model.Id, title = Model.Title })
                </div>
                <!-- /INFORMATION LAYOUT ITEM -->
            </div>
            <!-- INFORMATION LAYOUT -->
        </div>
提供ComplexPartialModel

public class GetOfferForAuctionDetail : ViewModel
{
    public OfferStatus OfferStatus { get; set; }

    public decimal Price { get; set; }
}
报价控制器

public ActionResult AuctionBestOffer(int auction)
    {
        var response = _offerService.GetBestOffer(auction);
        if (response.IsCompleted)
            return PartialView(response.Data);
        return null;
    }
拍卖控制器

public ActionResult AuctionDetail(string title,int id)
    {
        var response = _auctionService.AuctionDetail(id);
        if(response.IsCompleted)
        return View(response.Data);
        return RedirectToAction("Index", "Home", new {notificationError = response.Message});
    }
public List<GetAuctionDetailModel> GetModel(int id)
    {
        using (VerBiTeklifContext context = new VerBiTeklifContext())
        {
           var item =context.Auction.Where(s => s.Id == id).Include(s => 
           s.Offer);
          //mapping operations...
        }
    }
另一方面,提供了RactionMixModel

public class GetAuctionDetailModel : ViewModel
{
public int UserId { get; set; }

public int CategoryId { get; set; }

public int CityId { get; set; }

public AuctionBaseCategoryType BaseCategory { get; set; }

public AuctionBaseType AuctionBaseType { get; set; }

public string Title { get; set; }

public string Description { get; set; }

public DateTime EndDate { get; set; }

public decimal MaxPrice { get; set; }

public string Count { get; set; }

public bool IsActive { get; set; }

public List<GetOfferForAuctionDetail> OfferModels { get; set; }
}
公共类GetAuctionDetailModel:ViewModel { public int UserId{get;set;} public int CategoryId{get;set;} public int CityId{get;set;} public AuctionBaseCategoryType BaseCategory{get;set;} 公共AuctionBaseType AuctionBaseType{get;set;} 公共字符串标题{get;set;} 公共字符串说明{get;set;} 公共日期时间结束日期{get;set;} 公共十进制MaxPrice{get;set;} 公共字符串计数{get;set;} 公共bool IsActive{get;set;} 提供模式{get;set;}的公共列表 } 控制器

public ActionResult AuctionDetail(string title,int id)
    {
        var response = _auctionService.AuctionDetail(id);
        if(response.IsCompleted)
        return View(response.Data);
        return RedirectToAction("Index", "Home", new {notificationError = response.Message});
    }
public List<GetAuctionDetailModel> GetModel(int id)
    {
        using (VerBiTeklifContext context = new VerBiTeklifContext())
        {
           var item =context.Auction.Where(s => s.Id == id).Include(s => 
           s.Offer);
          //mapping operations...
        }
    }
公共列表GetModel(int-id)
{
使用(VerBiTeklifContext=new VerBiTeklifContext())
{
var item=context.Auction.Where(s=>s.Id==Id)。Include(s=>
s、 报价);
//映射操作。。。
}
}
我可以使用include方法执行相同的过程。我应该用哪一个


大家都做得很好…

请将您的型号和控制器添加到问题中,我很抱歉。我编辑了请将您的模型和控制器添加到问题中我很抱歉。我编辑