Click here to Skip to main content
15,912,578 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Cannot convert from AutoBuggi.Models.CarCategory to AutoBuggi.Repository.AutoBuggi.CarCategory

What I have tried:

This is my CategoryRepository Class file:
namespace AutoBuggi.Repository
{
    public class CategoryRepository
    {
        //private object dbCategory;
       
        public Guid SaveCategory(Models.CarCategory model)
        {
            try
            {
                using (var dbcontext = new AutoBuggiEntities())
                {
                    var dbCategory = new Models.CarCategory()
                    {
                        Id = Guid.NewGuid(),
                        CategoryId = model.CategoryId,
                        VariantName = model.VariantName
                    };
                    dbcontext.CarCategories.Add(dbCategory);
                    dbcontext.SaveChanges();
                }
            }
            catch(Exception)
            {
            }

            return Guid.Empty;
       }
    }
}



This is my Model Class File:
namespace AutoBuggi.Models
{
    public class CarCategory
    {
        public Guid Id { get; set; }
        public int CategoryId { get; set; }

        [DisplayAttribute(Name = "Variant Name")]
        public string VariantName { get; set; }
    }
}
Posted
Updated 16-Jul-18 1:19am
v2
Comments
Richard Deeming 12-Jun-18 10:12am    
You have two classes with the same name, but in different namespaces. That makes them completely different classes.

You are trying to assign an instance of one class to an instance of a different class. You can't do that.

1 solution

You should just create a
Repository.AutoBuggi.CarCategory
object instead of
Models.CarCategory
.
 
Share this answer
 

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