Mapping and metadata Info problem

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 лет назад
This is the error I get when I try var Distributor = DistributorManager.GetDistributorById(1);
Maybe some one could point me in the right direction please?


Mapping and metadata information could not be found for EntityType 'NopSolutions.NopCommerce.BusinessLogic.GF.Distributor'.
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.GF.Distributor'.

Source Error:

Line 27:             {
Line 28:                 if ((_distributors == null))
Line 29:                     _distributors = CreateObjectSet<Distributor>();
Line 30:                 return _distributors;
Line 31:             }


Source File: C:\Visual Studio 2010\Projects\Nop\Libraries\Nop.BusinessLogic\GF\NopObjectContext.cs    Line: 29

Stack Trace:

[InvalidOperationException: Mapping and metadata information could not be found for EntityType 'NopSolutions.NopCommerce.BusinessLogic.GF.Distributor'.]
   System.Data.Objects.ObjectContext.GetTypeUsage(Type entityCLRType) +8550105
   System.Data.Objects.ObjectContext.GetEntitySetFromContainer(EntityContainer container, Type entityCLRType, String exceptionParameterName) +39
   System.Data.Objects.ObjectContext.GetEntitySetForType(Type entityCLRType, String exceptionParameterName) +323
   System.Data.Objects.ObjectContext.CreateObjectSet() +57
   NopSolutions.NopCommerce.BusinessLogic.Data.NopObjectContext.get_Distributors() in C:\Visual Studio 2010\Projects\Nop\Libraries\Nop.BusinessLogic\GF\NopObjectContext.cs:29
   NopSolutions.NopCommerce.BusinessLogic.GF.DistributorManager.GetDistributorById(Int32 distributorId) in C:\Visual Studio 2010\Projects\Nop\Libraries\Nop.BusinessLogic\GF\DistributorManager.cs:14
   NopSolutions.NopCommerce.Web.Default.BindData() in C:\Visual Studio 2010\Projects\Nop\NopCommerceStore\Default.aspx.cs:58
   NopSolutions.NopCommerce.Web.Default.Page_Load(Object sender, EventArgs e) in C:\Visual Studio 2010\Projects\Nop\NopCommerceStore\Default.aspx.cs:46
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +91
   NopSolutions.NopCommerce.Web.BaseNopPage.OnLoad(EventArgs e) in C:\Visual Studio 2010\Projects\Nop\NopCommerceStore\Controls\BaseNopPage.cs:80
   System.Web.UI.Control.LoadRecursive() +74
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207



Class: Distributor.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NopSolutions.NopCommerce.BusinessLogic.GF
{
    public class Distributor
    {
        public int DistributorId { get; set; }
        public Guid DistributorGuid { get; set; }
        public string Name { get; set; }
        public string Address1 { get; set; }
        public string Address2 { get; set; }
        public string City { get; set; }
        public string State { get; set; }
        public string Zip { get; set; }
        public string PhoneNumber { get; set; }
        public int ParentId { get; set; }
        public int FillLimit { get; set; }
        public int FillCount { get; set; }
        public decimal DistributorCredit { get; set; }
        public decimal SalesTax { get; set; }
        public bool POEnabled { get; set; }
        public string CustomerNote { get; set; }
        public bool Blocked { get; set; }
        public string BlockedNote { get; set; }
        public Nullable<int> BlockedBy { get; set; }
        public Nullable<DateTime> BlockedDate { get; set; }
        public string PeachTreeId { get; set; }
    }
}


Class: DistributorManager.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NopSolutions.NopCommerce.BusinessLogic.Data;

namespace NopSolutions.NopCommerce.BusinessLogic.GF
{
    public class DistributorManager
    {
        public static Distributor GetDistributorById(int distributorId)
        {
            var db = ObjectContextHelper.CurrentObjectContext;
            return db.Distributors.SingleOrDefault(x => x.DistributorId == distributorId);
        }
        public IList<Distributor> GetAllDistributors()
        {
            var db = ObjectContextHelper.CurrentObjectContext;
            return db.Distributors.OrderBy(x => x.Name).ToList();
        }
        public void Save(Distributor distributor)
        {
            var db = ObjectContextHelper.CurrentObjectContext;
            if (distributor.DistributorId == 0)
            {
                db.Distributors.AddObject(distributor);
            }
            else
            {
                if (!db.IsAttached(distributor))
                    db.Distributors.Attach(distributor);
            }
            db.SaveChanges();
        }
    }
}


Class: NopObjectContext.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects;
using NopSolutions.NopCommerce.BusinessLogic.GF;

namespace NopSolutions.NopCommerce.BusinessLogic.Data
{
    public partial class NopObjectContext : ObjectContext
    {
        private ObjectSet<Distributor> _distributors;
        public ObjectSet<Distributor> Distributors
        {
            get
            {
                if ((_distributors == null))
                    _distributors = CreateObjectSet<Distributor>();
                return _distributors;
            }
        }
    }
}


Table: dbo.GF_Distributor

GO
/****** Object:  Table [dbo].[GF_Distributor]    Script Date: 11/03/2010 21:44:43 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[GF_Distributor](
  [DistributorId] [int] IDENTITY(1,1) NOT NULL,
  [DistributorGuid] [uniqueidentifier] ROWGUIDCOL  NOT NULL CONSTRAINT [DF_Distributor_DistributorGuid]  DEFAULT (newid()),
  [Name] [nvarchar](50) NOT NULL,
  [Address1] [nvarchar](50) NULL,
  [Address2] [nvarchar](50) NULL,
  [City] [nvarchar](50) NULL,
  [State] [nvarchar](50) NULL,
  [Zip] [nvarchar](10) NULL,
  [PhoneNumber] [nvarchar](20) NULL,
  [ParentId] [int] NOT NULL,
  [FillLimit] [int] NOT NULL,
  [FillCount] [int] NOT NULL,
  [DistributorCredit] [money] NOT NULL CONSTRAINT [DF_Distributors_CCredit]  DEFAULT ((0)),
  [SalesTax] [decimal](5, 3) NOT NULL CONSTRAINT [DF_Distributors_SalesTax]  DEFAULT ((0.00)),
  [POEnabled] [bit] NOT NULL CONSTRAINT [DF_Distributors_POEnabled]  DEFAULT ((0)),
  [CustomerNote] [nvarchar](max) NULL,
  [Blocked] [bit] NOT NULL,
  [BlockedNote] [nvarchar](max) NULL,
  [BlockedBy] [int] NULL,
  [BlockedDate] [datetime] NULL,
  [PeachtreeId] [nvarchar](7) NULL,
CONSTRAINT [PK_Distributors] PRIMARY KEY CLUSTERED
(
  [DistributorId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
13 лет назад
Sorry, I should of Triple checked it, PeachTreeId vs PeachtreeId.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.