SORU
11 Kasım 2013, PAZARTESİ


ASP.NET Kimlik karışıklığı DbContext

Varsayılan MVC 5 Uygulaması İdentityModels içinde bu kod parçası ile birlikte gelir.cs - bu kod parçası varsayılan şablonlar için: ASP.NET Kimlik işlemleri için

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public ApplicationDbContext()
        : base("DefaultConnection")
    {
    }
}

Yeni bir denetleyici Varlık Çerçevesi ile görüş kullanıyorum iskele ve bir "Yeni veri içeriği..." iletişim kutusunda, bu benim için oluşturulan.. oluşturun

using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;

namespace WebApplication1.Models
{
    public class AllTheOtherStuffDbContext : DbContext
    {
        // You can add custom code to this file. Changes will not be overwritten.
        // 
        // If you want Entity Framework to drop and regenerate your database
        // automatically whenever you change your model schema, please use data migrations.
        // For more information refer to the documentation:
        // http://msdn.microsoft.com/en-us/data/jj591621.aspx

        public AllTheOtherStuffDbContext() : base("name=AllTheOtherStuffDbContext")
        {
        }

        public System.Data.Entity.DbSet<WebApplication1.Models.Movie> Movies { get; set; }

    }
} 

Eğer başka bir kontrolör görünümü EF kullanıyorum iskele, bir Hayvan modeli için mesela bu yeni çizgi böyle public System.Data.Entity.DbSet<WebApplication1.Models.Movie> Movies { get; set; } - altı: sağ otomatik almak istiyorum

using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;

namespace WebApplication1.Models
{
    public class AllTheOtherStuffDbContext : DbContext
    {
        // You can add custom code to this file. Changes will not be overwritten.
        // 
        // If you want Entity Framework to drop and regenerate your database
        // automatically whenever you change your model schema, please use data migrations.
        // For more information refer to the documentation:
        // http://msdn.microsoft.com/en-us/data/jj591621.aspx

        public AllTheOtherStuffDbContext() : base("name=AllTheOtherStuffDbContext")
        {
        }

        public System.Data.Entity.DbSet<WebApplication1.Models.Movie> Movies { get; set; }
        public System.Data.Entity.DbSet<WebApplication1.Models.Animal> Animals { get; set; }

    }
} 

ApplicationDbContext (tüm ASP.NET Kimlik şeyler için) sırayla DbContextdevralan IdentityDbContext devralır. AllOtherStuffDbContext (kendi işim için) DbContext devralır.

Benim sorum ise şu:

Bu iki (ApplicationDbContext AllOtherStuffDbContext) diğer tüm modelleri kendi için kullanmalı mıyım? Ya da sadece varsayılan kullanarak bir problem olmamalı beri ApplicationDbContext otomatik kullanımı temel sınıfından türetir beri ** 15, ya da biraz havai olacak mı gerekir? Kullanmalısın, tek DbContext nesne uygulaması için tüm modeller (okudum bu yerde) yani ben bile kullanmayı düşünün hem ApplicationDbContext AllOtherStuffDbContext tek bir app? Ya da en iyi ASP.NET Kimlik ile MVC 5 uygulama nedir?

CEVAP
11 Kasım 2013, PAZARTESİ


Tek bir Bağlam sınıf İdentityDbContext devralmasını kullanırdım. Bu bağlamda sınıflar ve İdentityUser arasındaki ilişkiler ve İdentityDbContext Rolleri farkında olabilir. Bu İdentityDbContext çok az ek yük vardır, temelde iki DbSets ile düzenli bir DbContext. Kullanıcılar ve roller için.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • BaaaStuds's channel

    BaaaStuds's

    10 Mart 2009
  • failblog

    failblog

    17 HAZİRAN 2008
  • RaquelGamesBR

    RaquelGamesB

    20 HAZİRAN 2009