Aseem Bhardwaj

Aseem Bhardwaj

  • 1.6k
  • 114
  • 20.3k

Mapping of classes and sub classes by fluent NHibernate

May 21 2018 12:16 AM
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 (CtasTutes):-
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using codes.Models.BaseModel;  
  6. namespace codes.Models  
  7. {  
  8. public class CatsTute:ModelBase  
  9. {  
  10. public class Category:ModelBase  
  11. {  
  12. public virtual string Name { getset; }  
  13. public virtual string Image { getset; }  
  14. }  
  15. public class SubCat:ModelBase  
  16. {  
  17. public virtual int CatId { getset; }  
  18. public virtual string Name { getset; }  
  19. public virtual string Image { getset; }  
  20. }  
  21. public class Tutorial:ModelBase  
  22. {  
  23. public virtual string Name { getset; }  
  24. public virtual string Description { getset; }  
  25. public virtual int SubCatId { getset; }  
  26. }  
  27. }  
  28. }  
This is base model(ModelBase):-
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. namespace codes.Models.BaseModel  
  6. {  
  7. public class ModelBase  
  8. {  
  9. public virtual int Id { getset; }  
  10. public virtual DateTime CreatedOn { getset; }  
  11. public virtual DateTime UpdatedOn { getset; }  
  12. public virtual int Deleted { getset; }  
  13. public virtual bool Status { getset; }  
  14. }  
  15. }  
Here is mapping class(AllMapping):-
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using FluentNHibernate.Mapping;  
  6. namespace codes.Models.Mapping  
  7. {  
  8. public class AllMappings : ClassMap<CatsTute>  
  9. {  
  10. public AllMappings()  
  11. {  
  12. Table("CatsTute");  
  13. Id(x => x.Id, "Id").GeneratedBy.Identity().UnsavedValue(0);  
  14. Map(x => x.Status);  
  15. Map(x => x.CreatedOn);  
  16. Map(x => x.UpdatedOn);  
  17. Map(x => x.Deleted);  
  18. Map(x => x.Name).CustomSqlType("nvarchar(50)");  
  19. DynamicUpdate();  
  20. }  
  21. }  
  22. }