2010-08-26 16 views
5

बनाने नहीं मैं, दो टेबल, स्थानों और सुविधाएंधाराप्रवाह NHibernate Automapping बहुवचन तालिका नाम

वे दो वर्गों के लिए नक्शे,

public Location : Entity 
{ 
    //properties 
} 

public Facility : Entity 
{ 
    public virtual Location Location { get; set; } 
} 

सब कुछ बस dandy काम करता है जब तक मैं इस

की सुविधा बदल
public Facility : Location 
{ 

} 

अब मैं nHibernate से एक अपवाद कह

NHibernate.ADOException was unhandled by user code 
    Message=could not execute query 
InnerException: System.Data.SqlClient.SqlException 
     Message=Invalid object name 'Facility'. 
प्राप्त

किसी कारण से यह एसक्यूएल स्ट्रिंग में तालिका का बहुवचन नाम नहीं बना रहा है।

किसी भी मदद के लिए धन्यवाद!

संपादित

यह मेरे वर्तमान TableNameConvention

public class TableNameConvention : IClassConvention 
{ 
    public void Apply(FluentNHibernate.Conventions.Instances.IClassInstance instance) 
    { 
     instance.Table(Inflector.Net.Inflector.Pluralize(instance.EntityType.Name)); 
    } 
} 

सुविधा इकाई से इनहेरिट करते हैं, तो सुविधा इस पद्धति के माध्यम से चलाने करता है। जब यह स्थान से विरासत, यह Database diagram

public class AutoPersistenceModelGenerator : IAutoPersistenceModelGenerator 
{ 

    #region IAutoPersistenceModelGenerator Members 

    public AutoPersistenceModel Generate() 
    { 
     var mappings = new AutoPersistenceModel(); 
     mappings.AddEntityAssembly(typeof(Person).Assembly).Where(GetAutoMappingFilter); 
     mappings.Conventions.Setup(GetConventions()); 
     mappings.Setup(GetSetup()); 
     mappings.IgnoreBase<Entity>(); 
     mappings.IgnoreBase(typeof(EntityWithTypedId<>)); 
     mappings.UseOverridesFromAssemblyOf<AutoPersistenceModelGenerator>(); 

     return mappings; 

    } 

    #endregion 

    private Action<AutoMappingExpressions> GetSetup() 
    { 
     return c => 
     { 
      c.FindIdentity = type => type.Name == "Id"; 
     }; 
    } 

    private Action<IConventionFinder> GetConventions() 
    { 
     return c => 
     { 
      c.Add<BHP.DEC.Data.NHibernateMaps.Conventions.ForeignKeyConvention>(); 
      c.Add<BHP.DEC.Data.NHibernateMaps.Conventions.HasManyConvention>(); 
      c.Add<BHP.DEC.Data.NHibernateMaps.Conventions.HasManyToManyConvention>(); 
      c.Add<BHP.DEC.Data.NHibernateMaps.Conventions.ManyToManyTableNameConvention>(); 
      c.Add<BHP.DEC.Data.NHibernateMaps.Conventions.PrimaryKeyConvention>(); 
      c.Add<BHP.DEC.Data.NHibernateMaps.Conventions.ReferenceConvention>(); 
      c.Add<BHP.DEC.Data.NHibernateMaps.Conventions.TableNameConvention>(); 
     }; 
    } 

    /// <summary> 
    /// Provides a filter for only including types which inherit from the IEntityWithTypedId interface. 
    /// </summary> 

    private bool GetAutoMappingFilter(Type t) 
    { 
     return t.GetInterfaces().Any(x => 
             x.IsGenericType && 
             x.GetGenericTypeDefinition() == typeof(IEntityWithTypedId<>)); 
    } 
} 
+0

फ्लुएंट एनएचबर्ननेट तालिका के नामों का कोई बहुवचन नहीं करता है, या उस मामले के लिए कुछ भी नहीं। आपको डेविड जैसे एक सम्मेलन को बनाने और वहां के नेट इन्फ्लेक्टरों में से एक का उपयोग करने की आवश्यकता है। –

+0

तालिकानाम कॉन्फ़्रेंस वहां है, लेकिन किसी कारण से जब मैं स्थान से उत्तराधिकारी के लिए सुविधा बदलता हूं, तो जब यह असेंबली स्कैन करता है तो धाराप्रवाह सेटअप अब इसे नहीं ढूंढता है। –

+0

जैसा कि, ऐसा लगता है कि आप स्थान को अन्य बेस क्लास के रूप में देख रहे हैं, इस मामले में निम्नलिखित कार्य कर सकते हैं: मैपिंग्स। इग्नोरबेस (); या किसी टेबल-प्रति-सबक्लास की तरह कुछ के लिए जा रहे हैं? – David

उत्तर

8

आप एक convention सेट नहीं

संपादित 2 मैं सब कुछ पोस्ट करता हूँ लगा है ...?

public class TableNameConvention : IClassConvention 
{ 
    public void Apply(FluentNHibernate.Conventions.Instances.IClassInstance instance) 
    { 
     string typeName = instance.EntityType.Name; 

     instance.Table(Inflector.Net.Inflector.Pluralize(typeName)); 
    } 
} 
+0

हाँ वहां है। कुछ कारणों से जब मैं स्थान सुविधा से उत्तराधिकारी की सुविधा बदलता हूं, तो इस तालिका नाम सम्मेलन में शामिल नहीं किया जाता है। –

+0

ईह, दिलचस्प। तो क्या आप एक विरासत रणनीति का उपयोग कर रहे हैं? - http://jagregory.com/writings/fluent-nhibernate-auto-mapping-and-base-classes/ – David

+0

हाँ। यह उदाहरण में एक जैसा दिखता है। यहां एक लिंक दिया गया है: http://yfrog.com/1gdhfp –

1

यह एक पुरानी सवाल है, लेकिन दूसरों की खातिर जो एक जवाब की तलाश में इस पर ठोकर के लिए, आप भी एक सम्मेलन का उपयोग करता है बना सकते हैं में निर्मित PluralizationService कि एफई के साथ आता है:

public class TableNameConvention : IClassConvention 
{ 
    public void Apply(IClassInstance instance) 
    { 
     string typeName = instance.EntityType.Name; 
     instance.Table(PluralizationService.CreateService(CultureInfo.CurrentCulture).Pluralize(typeName)); 

    } 
} 
+0

निबर्ननेट और ईएफ का दिलचस्प मिश्रण। हमें इस परियोजना के लिए साल पहले ईएफ का उपयोग करने की अनुमति नहीं थी। –