Click here to Skip to main content
15,879,474 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
hi friends,

I am getting problem while mapping my model class(with subclasses).
I am not getting the Name. It shows error while writing the code.
The error is "CatsTute' does not contain a definition for 'Name' and no extension method 'Name' accepting a first argument of type 'CatsTute' could be found (are you missing a using directive or an assembly reference?)":
Here is main model (CatsTutes):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using codes.Models.BaseModel;

namespace codes.Models
{
    public class CatsTute:ModelBase
    {
        public class Category:ModelBase
        {
            public virtual string Name { get; set; }
            public virtual string Image { get; set; }
        }
        public class SubCat:ModelBase
        {
            public virtual int CatId { get; set; }
            public virtual string Name { get; set; }
            public virtual string Image { get; set; }
        }
        public class Tutorial:ModelBase
        {
            public virtual string Name { get; set; }
            public virtual string Description { get; set; }
            public virtual int SubCatId { get; set; }
        }
    }
}

This is base model(ModelBase):-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace codes.Models.BaseModel
{
    public class ModelBase
    {
        public virtual int Id { get; set; }
        public virtual DateTime CreatedOn { get; set; }
        public virtual DateTime UpdatedOn { get; set; }
        public virtual int Deleted { get; set; }
        public virtual bool Status { get; set; }
    }
}

Here is mapping class(AllMapping):-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FluentNHibernate.Mapping;

namespace codes.Models.Mapping
{
    public class AllMappings : ClassMap<CatsTute>
    {
        public AllMappings()
        {
            Table("CatsTute");
            Id(x => x.Id, "Id").GeneratedBy.Identity().UnsavedValue(0);
            Map(x => x.Status);
            Map(x => x.CreatedOn);
            Map(x => x.UpdatedOn);
            Map(x => x.Deleted);
            Map(x => x.Name).CustomSqlType("nvarchar(50)");   <========Here is the problem
            DynamicUpdate();
        }
    }
}


What I have tried:

I don't know what to do............
Posted
Updated 21-May-18 8:31am
v3
Comments
Richard Deeming 21-May-18 14:32pm    
The error message is perfectly clear: your CatsTute class does not contain a property called Name.

There are three nested classes within the CatsTute class which do contain a property called Name. But the CatsTute class itself does not have a Name property.

1 solution

The problem seems to me that 'Name' is defined three times, so maybe you need to use unique names like Name1, Name2, Name3.
Here is an article on CodeProject which explains mapping subclasses: Inheritance mapping strategies in Fluent Nhibernate[^]
 
Share this answer
 
v2
Comments
Richard Deeming 21-May-18 14:28pm    
Except all three Name properties are defined in nested classes. :)

(The lack of indentation doesn't help.)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900