2012-01-19 8 views
8

मैं इस परिदृश्य में db पीढ़ी के साथ एक समस्या है।इकाई की रूपरेखा कोड पहले ही नाम के साथ लेकिन अलग नामस्थान में दो संस्थाओं

namespace First.Entities 
{ 
    #region using section 

    using System.Collections.Generic; 
    using System.ComponentModel.DataAnnotations; 
    using System.Data.Entity.ModelConfiguration; 
    using System.Diagnostics.CodeAnalysis; 

    #endregion 

    [Table("First_Project")] 
    public class Project 
    { 
     [Key] 
     public int Id 
     { 
      get; 
      set; 
     } 

     [Required] 
     [MaxLength(1000)] 
     public string Name 
     { 
      get; 
      set; 
     } 
    } 
} 

2.cs परियोजना इकाई द्वितीय में। एंटीटीज नेमस्पेस द्वितीय_Project तालिका में मैप किया गया।

namespace Second.Entities 
{ 
    #region using section 

    using System.Collections.Generic; 
    using System.ComponentModel.DataAnnotations; 
    using System.Data.Entity.ModelConfiguration; 
    using System.Diagnostics.CodeAnalysis; 

    #endregion 

    [Table("Second_Project")] 
    public class Project 
    { 
     [Key] 
     public int Id 
     { 
      get; 
      set; 
     } 

     [Required] 
     [MaxLength(1000)] 
     public string Name 
     { 
      get; 
      set; 
     } 
    } 
} 

3.cs फ़ाइल DbContext

namespace DataContext 
{ 
    #region using section 

    using System.Collections.Generic; 
    using System.Data.Common; 
    using System.Data.Entity; 
    using System.Data.Entity.Infrastructure; 
    using System.Data.Entity.ModelConfiguration.Conventions; 
    using System.Diagnostics.CodeAnalysis; 
    using First.Entities; 
    using Second.Entities; 

    #endregion 

    public class MyEntities : DbContext 
    { 
     public DbSet<First.Entities.Project> FirstProjects { get; set; } 

     public DbSet<Second.Entities.Project> SecondProjects { get; set; } 
    } 
} 

कृपया मदद करते हैं।

+5

आपको क्या त्रुटि मिलती है? तुम्हें किसमें मदद चाहिए? –

+0

ऐसे परिदृश्य में डेटाबेस बनाना संभव नहीं है। त्रुटि है: – mehanik

+0

प्रकार 'Second.Entities.Project' मैप नहीं किया गया था। जांचें कि इग्नोर विधि या NotMappedAttribute डेटा एनोटेशन का उपयोग करके इस प्रकार को स्पष्ट रूप से बहिष्कृत नहीं किया गया है। सत्यापित करें कि प्रकार को कक्षा के रूप में परिभाषित किया गया था, आदिम, नेस्टेड या जेनेरिक नहीं है, और EntityObject से प्राप्त नहीं होता है। – mehanik

उत्तर

10

यह संभव नहीं है। एकल संदर्भ प्रकार में प्रत्येक मैप किए गए इकाई के लिए कक्षा का नाम (नामस्थान के बिना) अद्वितीय होना चाहिए। कारण this answer में उल्लिखित है।

आपको विभिन्न वर्ग नामों का उपयोग करना होगा। Btw। विभिन्न (अधिक विशिष्ट) वर्ग नामों का उपयोग करके आपके कोड को बेहतर पठनीय बनाता है और आपके प्रकार बेहतर उपयोग योग्य होते हैं।

संबंधित मुद्दे