Add new Table in NopModel.edmx

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 years ago
Hello,

i am try to add a new table in a NopModel.edmx file and create new page and add its .cs file in business logic
all work perfectly but its give error
"Mapping and metadata information could not be found for EntityType 'NopSolutions.NopCommerce.BusinessLogic.Workshops.Workshop'. "

here Workshop is table which was i add in database and nopmodel.edmx file.
error is come at runtime at the build process done sucessfully.

i think problem with entity it was not find the "Workshop" entity in edmx file
i was also update edmx file and add workshop entity.

please help where the problem...
12 years ago
follow this article
http://blogs.planetcloud.co.uk/mygreatdiscovery/post/How-to-extend-nopCommerce.aspx
12 years ago
Hi

Errors of type Mapping and metadata information could not be found for EntityType can be caused by a number of things but the most common I find with nop are where the property names in the associated class (POCO Class) are not exactly the same case as the property in the NopModel.edmx file.

ProductID / ProductId will produce this error.

Check them in Workshop.cs (think this is your class?)

other causes maybe;-

    * Misspelled properties (case-sensitive!)
    * Properties missing in the POCO class
    * Type mismatches between the POCO and entity-type (e.g., int instead of long)
    * Enums in the POCO (EF doesn't support enums right now as I understand)

I would also watch for nullable types in the db and make the POCO class have nullable types (not required for string).

HTH
12 years ago
Thanks U su much i found the problem

Workshop_ID which is in class WorkshopID so its create problem.
12 years ago
The link above does not work exactly with version 1.9
http://blogs.planetcloud.co.uk/mygreatdiscovery/post/How-to-extend-nopCommerce.aspx

not even close to a good example for v1.9 and lends itself to confusion and total crash for people that don't have a clue as to how EF works along with the fact that the POCO T4 auto generation has been removed and then to top it off that example is for v1.8 I am guessing from reading on these forums for days.

Something about the link missing the examples for the interfaces and such for version 1.9

Can someone point to a simple clear example for v1.9 to add a new attribute to any table or can some point to a clear example how to add a new table to the edmx

I make it through most of the example in the link but crash and burn when it came to the part of adding the manager on this line
       var db = no ObjectContextHelper.CurrentObjectContext;

It does like at all the ObjectContextHelper.

I am new to ef and POCO and again to top it off nop hand crafted the .tt files and as such even examples found on the web can not help with this because nop wrote allot from scratch.  I have been reading for a week now trying to figure this out and to no avail i am still totally lost but have learned a great deal and found many exciting approaches nop took but again I am totally lost.

thanks for everyone involved this is a great product and I am able to accomplish allot of custom development and i understand a great deal about certain classes and such, but again my skills with EF POCO hand written interfaces and such are lacking very much

Thanks again
12 years ago
I couldn't agree more.

I finally got it working with some codesnippets found on this forum:

Hope you can use my code below. I have added a table "MOD_License" and all is working.
You can use the blogpost for adding the table in the .emdx and use the code below for the rest.





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

namespace NopSolutions.NopCommerce.BusinessLogic.MOD
{
    public partial class MOD_License
    {
        public int LicenseID { get; set; }
        public string Email { get; set; }
        public string WebshopData { get; set; }
        public int ProductVariantID { get; set; }
        public string SKU { get; set; }
        public int Type { get; set; }
        public string LicenseBasedOn { get; set; }
        public string ReleasedLicenseNo { get; set; }
    }
}

namespace NopSolutions.NopCommerce.BusinessLogic.Data
{
    /// <summary>
    /// Represents a nopCommerce object context
    /// </summary>
    public partial class NopObjectContext : ObjectContext
    {
        private ObjectSet<MOD_License> _MOD_Licenses;

        public ObjectSet<MOD_License> MOD_Licenses
        {
            get
            {
                if ((_MOD_Licenses == null))
                    _MOD_Licenses = CreateObjectSet<MOD_License>();
                return _MOD_Licenses;
            }
        }
    }
}

namespace NopSolutions.NopCommerce.BusinessLogic.MOD
{
    public class MOD_LicenseManager
    {
        public static MOD_License GetMOD_LicenseById(int LicenseId)
        {
            var db = IoC.Resolve<NopObjectContext>();
            return db.MOD_Licenses.SingleOrDefault(x => x.LicenseID == LicenseId);
        }

        public static MOD_License GetMOD_LicenseByEmail(string sEmail)
        {
            var db = IoC.Resolve<NopObjectContext>();
            return db.MOD_Licenses.SingleOrDefault(x => x.Email.ToLower() == sEmail.ToLower());
        }

        public static IList<MOD_License> GetAllLicenses()
        {
            var db = IoC.Resolve<NopObjectContext>();

            //                        orderby s.ReleasedLicenseNo, s.LicenseID descending
            var query = from s in db.MOD_Licenses
                        orderby s.LicenseID descending
                        select s;

            return query.ToList();
            //return db.MOD_Licenses.OrderBy(x => x.ReleasedLicenseNo).ToList();
        }

        public static void Delete_LicenseById(int LicenseId)
        {
            var license = GetMOD_LicenseById(LicenseId);
            if (license == null)
                return;

            var db = IoC.Resolve<NopObjectContext>();
            if (!db.IsAttached(license))
                db.MOD_Licenses.Attach(license);
            db.DeleteObject(license);
            db.SaveChanges();
        }

        public static void Save(MOD_License license)
        {
            var db = IoC.Resolve<NopObjectContext>();

            if (license.LicenseID == 0)
            {
                // new record
                db.MOD_Licenses.AddObject(license);
            }
            else
            {
                // existing record
                if (!db.IsAttached(license))
                    db.MOD_Licenses.Attach(license);
            }

            db.SaveChanges();
        }
    }
}


12 years ago
post deleted
12 years ago
Thank you very much.  I found this particular line in your snippet very very helpful and it solved my issues

var db = IoC.Resolve<NopObjectContext>();

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