2016-03-30 26 views
1

Şu anda Entity Framework ile MVC 3 kullanıyorum 5. Yani bu MachineController denir benim denetleyicisi geçerli:ASP.NET MVC 3 - alma yinelenen satırlar

using System; 
using System.Collections.Generic; 
using System.Data; 
using System.Data.Entity; 
using System.Linq; 
using System.Web; 
using System.Web.Mvc; 
using Gestion_Machines.Models; 

namespace Gestion_Machines.Controllers 
{ 
    public class MachineController : Controller 
    { 
     private RTTV5Entities db = new RTTV5Entities(); 

     // 
     // GET: /Machine/ 

     public ViewResult Index() 
     { 
      return View(db.tMachines.ToList()); 
     } 

     // 
     // GET: /Machine/Details/5 

     public ViewResult Details(string id) 
     { 
      tMachines tmachines = db.tMachines.Find(id); 
      return View(tmachines); 
     } 

     // 
     // GET: /Machine/Create 

     public ActionResult Create() 
     { 
      return View(); 
     } 

     // 
     // POST: /Machine/Create 

     [HttpPost] 
     public ActionResult Create(tMachines tmachines) 
     { 
      if (ModelState.IsValid) 
      { 
       db.tMachines.Add(tmachines); 
       db.SaveChanges(); 
       return RedirectToAction("Index"); 
      } 

      return View(tmachines); 
     } 

     // 
     // GET: /Machine/Edit/5 

     public ActionResult Edit(string id) 
     { 
      tMachines tmachines = db.tMachines.Find(id); 
      return View(tmachines); 
     } 

     // 
     // POST: /Machine/Edit/5 

     [HttpPost] 
     public ActionResult Edit(tMachines tmachines) 
     { 
      if (ModelState.IsValid) 
      { 
       db.Entry(tmachines).State = EntityState.Modified; 
       db.SaveChanges(); 
       return RedirectToAction("Index"); 
      } 
      return View(tmachines); 
     } 

     // 
     // GET: /Machine/Delete/5 

     public ActionResult Delete(string id) 
     { 
      tMachines tmachines = db.tMachines.Find(id); 
      return View(tmachines); 
     } 

     // 
     // POST: /Machine/Delete/5 

     [HttpPost, ActionName("Delete")] 
     public ActionResult DeleteConfirmed(string id) 
     {    
      tMachines tmachines = db.tMachines.Find(id); 
      db.tMachines.Remove(tmachines); 
      db.SaveChanges(); 
      return RedirectToAction("Index"); 
     } 

     protected override void Dispose(bool disposing) 
     { 
      db.Dispose(); 
      base.Dispose(disposing); 
     } 
    } 
} 

Bu otomatik benim Endeksi View var , ayrıntıları ve Düzen oluşturma, silme ile birlikte kontrolör oluşturduktan sonra oluşturulan: Ben uygun tablo olsun, ancak diğer kayıtlar eksik iken nasılsa O yinelenen kayıtları içeren /Machine/Index eriştiklerinde

@model IEnumerable<Gestion_Machines.Models.tMachines> 

@{ 
    ViewBag.Title = "Index"; 
} 

<link href="../../Content/machine.css" rel="stylesheet" /> 
<h2>Index</h2> 

<p> 
    @Html.ActionLink("Create New", "Create") 
</p> 
<table> 
    <tr> 
     <th> 
      NomMachine 
     </th> 
     <th> 
      Fabriquant 
     </th> 
     <th> 
      MachineSection 
     </th> 
     <th> 
      TypeMachine 
     </th> 
     <th> 
      VitesseMaxi 
     </th> 
     <th> 
      NbPistes 
     </th> 
     <th> 
      UniteVitesse 
     </th> 
     <th> 
      UniteEntrante 
     </th> 
     <th> 
      UniteSortante 
     </th> 
     <th> 
      Efficience 
     </th> 
     <th> 
      EfficienceGlobale 
     </th> 
     <th> 
      VitesseMoy 
     </th> 
     <th> 
      TauxPanne 
     </th> 
     <th> 
      TauxArret 
     </th> 
     <th> 
      RunM2 
     </th> 
     <th> 
      RunML 
     </th> 
     <th> 
      TCO 
     </th> 
     <th> 
      Section 
     </th> 
     <th> 
      Atelier 
     </th> 
     <th> 
      TransfertFocus 
     </th> 
     <th> 
      MagasinEntree 
     </th> 
     <th> 
      MagasinSortie 
     </th> 
     <th> 
      NbPalettes 
     </th> 
     <th> 
      MagasinSortieWIP 
     </th> 
     <th> 
      MagasinSortieSF 
     </th> 
     <th> 
      MagasinSortieFG 
     </th> 
     <th> 
      Qualite 
     </th> 
     <th> 
      BlistersPerCarton 
     </th> 
     <th> 
      SeuilProdAtteint 
     </th> 
     <th> 
      TpsChgmtOf 
     </th> 
     <th> 
      QteProdSaisie 
     </th> 
     <th> 
      Active 
     </th> 
     <th></th> 
    </tr> 

@foreach (var item in Model) { 
    <tr> 
     <td> 
      @Html.DisplayFor(modelItem => item.NomMachine) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.Fabriquant) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.MachineSection) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.TypeMachine) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.VitesseMaxi) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.NbPistes) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.UniteVitesse) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.UniteEntrante) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.UniteSortante) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.Efficience) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.EfficienceGlobale) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.VitesseMoy) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.TauxPanne) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.TauxArret) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.RunM2) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.RunML) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.TCO) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.Section) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.Atelier) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.TransfertFocus) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.MagasinEntree) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.MagasinSortie) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.NbPalettes) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.MagasinSortieWIP) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.MagasinSortieSF) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.MagasinSortieFG) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.Qualite) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.BlistersPerCarton) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.SeuilProdAtteint) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.TpsChgmtOf) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.QteProdSaisie) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.Active) 
     </td> 
     <td> 
      @Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) | 
      @Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) | 
      @Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ }) 
     </td> 
    </tr> 
} 

</table> 

Yani benim sorundur. Denetleyicide veya Görünümde, her ikisi de oluşturulduğu her şeyi değiştirmedim.

ps: veritabanım çoğaltılmış olanları içermiyor.

düzenleme: Tablo görünümünde tam olarak 49 kayıt görüyorum. Temelde sadece bir kez 6 kez tekrarlanan 3 farklı kayıt, bir diğeri tekrar tekrar 42 kez tekrarlanır. Özgün veritabanı tablomda, çoğaltmanın olmadığı 49 kayıt var.

sunucu kaşif benim Makineleri tablosunu görüntülemek için güvenilir olması (sağ tıklayıp> "Tablo Göster Verileri"), aşağıdaki hata var: This Database Cannot be imported. It is either an unsupported SQL Server version or an unsupported database compatibility.

Şu anda bu hata için arıyorum.

+0

Makineler tablosunda kaç kayıt var? Ekranda kaç kişi görüyorsun? – Shyju

+0

Makineler tablosu görünümünde 49 kayıt görüyorum. Temelde sadece 3 farklı olan. Bunlardan biri altı kez tekrarladı, bir kez tekrar tekrar 42 kez tekrarlandı ve bir diğeri tekrarlandı. Gerçek veritabanımda, kopyalarımın olmadığı 49 kayıt var. Not: Fark ettim ki, "Sunucu Verilerini Göster" seçeneğini tıklatmaya çalıştığımda, "Bu Veritabanı alınamıyor. Bu desteklenmeyen bir SQL Server sürümü veya desteklenmeyen bir veritabanı uyumluluğudur" şeklinde bir hata alıyorum. Konuştuğumuz gibi bu sorunu arıyorum. – Angelo

+0

Uyumluluk sorunu çözüldü, artık tablo verilerimi Visual Studio'da düzgün gösterebiliyorum. Yine de, uygulamayı yürütürken hala yinelenen satırları alıyorum. Bu sadece belirli bir tablo ile olur. Neden olmasın diye emin değilim. – Angelo

cevap

1

Aslında ben, tools > Extensions and Updates > Updates gidin benim Visual Studio güncellemenizi VS son sürümü güncellendi emin olmak için karar kadar bu benim için sorun çözüldü beni deli ediyordu, birkaç hafta önce bu sorun vardı .

Yardım ettim

+0

Sadece çalıştım, güncellemedim ama VS'nin yeni bir sürümünü kurdum ve sorun çözüldü. Bence güncelleme işe yarayacaktı .. daha önce nerede bulundun? :) – Angelo