Mapping and metadata information could not be found for EntityType

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 年 前
Hi Experts,
I am regular user of NopCommerce but mostly i was working in previous  version <1.7. But now i started nopCommerce 1.7 in 2010 VS.

1.
I added one table called :
tjq_users actually this was in my previous e-commerce.

Having Field Like:

public partial class tjq_Users : BaseEntity
    {
        public tjq_Users()
        {
        }
        public int UserID { get; set; }
        public int UserAccessLevel { get; set; }
        public DateTime UserDateStamp { get; set; }
        public bool UserValidated { get; set; }
        public DateTime UserLastAccessDate { get; set; }
        public bool UserActive { get; set; }
        public DateTime UserExpirationDate { get; set; }
        public bool UserNews { get; set; }
        public bool UserMailingList { get; set; }
        public DateTime UserSubscribeDate { get; set; }
        public DateTime UserSubscribeCancelDate { get; set; }
        public string UserSubscriptionDescription { get; set; }
        public int UserSubscriptionTerm = 1;
        public float UserMonthlyRate { get; set; }
        public DateTime UserNextChargeDate { get; set; }
        public float UserNextChargeAmount { get; set; }
      
        public string UserEmailAddress { get; set; }
        public string UserFirstName { get; set; }
        public string UserLastName { get; set; }
        public string UserPassword { get; set; }
        public bool UserNotifyForumPostAll{get;set;}
        public bool UserNotifyNews{get;set;}
        public bool UserNotifyForumPostRelated{get;set;}
        public bool UserNotifyBlogPost { get; set; }
        public string UserNickName { get; set; }
        public string UserReferralAffiliateID { get; set; }
        public int UserReferralUserID { get; set; }
        
     }
Its because i just want to store user information in both system from NopCommerce registration Form.

2. I did pull in the NopModel.edmx.
3. get inside of NopObjectContext.css and added following code:
  public ObjectSet<tjq_Users> tjq_Users
        {
            get
            {
                if ((_tjq_Users == null))
                {
                    _tjq_Users = CreateObjectSet<tjq_Users>();
                }
                return _tjq_Users;
            }

        }
        private ObjectSet<tjq_Users> _tjq_Users;
4.  I did call on CustomerManager.cs like below
var tjq = context.tjq_Users.CreateObject();

            tjq.UserID = 0;
            tjq.UserFirstName = "sunil";
            tjq.UserLastName = "paudel";
            tjq.UserEmailAddress = "[email protected]";
            tjq.UserPassword = "password";
            tjq.UserReferralAffiliateID = "aaaa";
            tjq.UserNotifyForumPostAll = true;
            tjq.UserNotifyNews = true;
            tjq.UserNotifyForumPostRelated = true;
            tjq.UserNotifyBlogPost = true;
            tjq.UserNickName = "test name";
            tjq.UserReferralUserID = 1;
            tjq.UserAccessLevel = 0;
            tjq.UserDateStamp = DateTime.Now;
            tjq.UserValidated = true;
            tjq.UserLastAccessDate = DateTime.Now;
            tjq.UserActive = true;
            tjq.UserExpirationDate = DateTime.Now.AddDays(300);
            tjq.UserNews = false;
            tjq.UserMailingList = false;
            tjq.UserSubscribeDate = DateTime.Now;
            tjq.UserSubscribeCancelDate = DateTime.Now.AddDays(300);
            tjq.UserSubscriptionDescription = "teest";
            tjq.UserSubscriptionTerm = 1;
            tjq.UserMonthlyRate = 1010;
            tjq.UserNextChargeDate = DateTime.Now.AddDays(300);
            tjq.UserNextChargeAmount = 100;
            context.tjq_Users.AddObject(tjq);
           context.SaveChanges();
5. Finally i get following error

Mapping and metadata information could not be found for EntityType 'NopSolutions.NopCommerce.BusinessLogic.tjq_UsersManagement.tjq_Users'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Mapping and metadata information could not be found for EntityType 'NopSolutions.NopCommerce.BusinessLogic.tjq_UsersManagement.tjq_Users'.

Source Error:

Line 108:                if ((_tjq_Users == null))
Line 109:                {
Line 110:                    _tjq_Users = CreateObjectSet<tjq_Users>();
Line 111:                }
Line 112:                return _tjq_Users;


Source File: D:\Projects\NopCommerce\from client\test\Source\Libraries\Nop.BusinessLogic\Data\NopObjectContext.cs    Line: 110


Mapping and metadata information could not be found for EntityType 'NopSolutions.NopCommerce.BusinessLogic.tjq_UsersManagement.tjq_Users'.


Thanks in Advance
Khem
13 年 前
i got same problem, so far do you have any solution yet?
13 年 前
You are only missing one step.


1. Open up the NopModel.edmx file in VS.  Right click anywhere in the window and select 'Update Model from database'.  This will start a wizard.  The wizard will ask you what tables you want to add your schema.  Scroll down and select your new table "tjq_Users".  Keep in mind that your class file must match this EXACTLY.  Click ok/save/etc. and rebuild.  You should now have everything working ok.

NOTE:  I can't stress this enough.  If you start pulling your hair out over the error you mentioned in your OP, stop and go through each property and ensure that everything matches EXACTLY between your db and your class file.  Chances are you probably have UserId in your db and UserID in your class file or something simple like that.  It happens to everyone.

FINALLY:  Keep in mind that any future upgrades will overwrite your model if not properly accounted for.  I would recommend creating a separate project that has a seperate data model.  I keep promising a tutorial on how to do this but I just haven't finished it yet.  I doubt you would have too much trouble figuring it out your self.  Good luck.

t
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.