2013-05-03 1 views
0

C# 및 SQL Server 2005를 사용하여 ASP .Net MVC 3 응용 프로그램을 개발 중입니다. 기록 된 사용자 유형에 따라 인터페이스를 사용자 정의하고 싶습니다. Microsoft 사이트에서 this tuto을 (를) 팔로우했으며 ActionLog 인스턴스를 필터 클래스 (ActionLogFilterAttribute)에서 사용할 때 막혔습니다. 사실이 클래스는 Entity Framework의 '코드 첫 번째'메소드를 사용하여 프로젝트를 생성했기 때문에 'StoreDB.designer.cs'클래스에 선언되어 있습니다.필터링 방법 ASP MVC에서 로그인 하시겠습니까?

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Data.Entity; 
using System.ComponentModel.DataAnnotations; 
namespace MvcApplication2.Models 
{ 
    public class GammeContext : DbContext 
    { 
     public GammeContext() 
     { 
      Database.SetInitializer(new DropCreateDatabaseIfModelChanges<GammeContext>()); 
     } 

     public DbSet<Account> Accounts { get; set; } 
     public DbSet<Ns_AFaire> Ns_AFaires { get; set; } 
     public DbSet<Famille> Familles { get; set; } 
     public DbSet<Fonction> Fonctions { get; set; } 
     public DbSet<Fonction_Poste> Fonction_Postes { get; set; } 
     public DbSet<Gamme> Gammes { get; set; } 
     public DbSet<Historique> Historiques { get; set; } 
     public DbSet<Ligne> Lignes { get; set; } 
     public DbSet<Phase> Phases { get; set; } 
     public DbSet<Poste> Postes { get; set; } 
     public DbSet<Produit> Produits { get; set; } 
     public DbSet<Profile_Ga> Profil_Gas { get; set; } 
     public DbSet<Sous_Famille> Sous_Familles { get; set; } 
     public DbSet<UF> UFs { get; set; } 
     public DbSet<User> Users { get; set; } 
     public DbSet<Num_Serie> Num_Series { get; set; } 

     protected override void OnModelCreating(DbModelBuilder modelBuilder) 
     { 
      modelBuilder.Conventions.Remove<System.Data.Entity.ModelConfiguration.Conventions.PluralizingTableNameConvention>(); 
     } 
    } 
} 

을이 내가 만든 필터 클래스 : I 컨텍스트 만이 클래스 그래서

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.Mvc; 
using MvcApplication2.Models; 

namespace MvcApplication2.Filters 
{ 
    public class ActionLogFilterAttribute : ActionFilterAttribute, IActionFilter 
    { 
     public override void OnActionExecuting(ActionExecutingContext filterContext) 
     { 
      GammeContext db = new GammeContext(); 
      ActionLog log = new ActionLog() 
      { 
       Controller = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName, 
       Action = filterContext.ActionDescriptor.ActionName, 
       IP = filterContext.HttpContext.Request.UserHostAddress, 
       DateTime = filterContext.HttpContext.Timestamp 
      }; 
      db.AddToActionLogs(log); 
      db.SaveChanges(); 
      base.OnActionExecuting(filterContext); 
     } 
    } 
} 

는 어떤 솔루션이있다 ??

답변

0

그가 사용중인 ActionLog 인스턴스는 자신의 ActionLog 테이블과 관련된 Enitity입니다.

당신이해야 할 일은 당신 자신의 ActionLog 엔티티를 추가하는 것입니다 - 그게 전부예요 :)

+0

thx 당신의 대답은 ,,,하지만 어떻게 알 수 있습니까? – anouar

+0

모델과 매퍼 클래스를 추가하고'public DbSet ActionLogs {get; 세트; }'를 GammeContext에 추가합니다. – Dietz

관련 문제