Error while creating a new table with fk relations

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 年 前
im using nop 1.8
Im trying to create a blogpicture table, which is a copy of the productpicture table.
But when i call bold line below i get the following error


Error:
The navigation property of type 'NopSolutions.NopCommerce.BusinessLogic.Media.Picture' is not a single implementation of 'System.Collections.Generic.ICollection`1[T]'.



Code that fails:        
public static BlogPicture InsertBlogPicture(int blogPostId,
            int pictureId, int displayOrder)
        {
          var context = ObjectContextHelper.CurrentObjectContext;

          var blogPicture = context.BlogPicture.CreateObject();
          blogPicture.BlogPostId = blogPostId;
          blogPicture.PictureId = pictureId;
          blogPicture.DisplayOrder = displayOrder;

          context.BlogPicture.AddObject(blogPicture);          
context.SaveChanges();

          return blogPicture;
        }



This is my BlogPicture class
[code]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NopSolutions.NopCommerce.BusinessLogic.Media;

namespace NopSolutions.NopCommerce.BusinessLogic.Content.Blog
{
  /// <summary>
  ///
  /// </summary>
  public partial class BlogPicture : BaseEntity
  {
    #region Properties
    /// <summary>
    /// Gets or sets the ProductPicture identifier
    /// </summary>
    public int BlogPictureId { get; set; }

    /// <summary>
    /// Gets or sets the product identifier
    /// </summary>
    public int BlogPostId { get; set; }

    /// <summary>
    /// Gets or sets the picture identifier
    /// </summary>
    public int PictureId { get; set; }

    /// <summary>
    /// Gets or sets the display order
    /// </summary>
    public int DisplayOrder { get; set; }
    #endregion



    #region Custom Properties
    /// <summary>
    /// Gets the picture
    /// </summary>
    public Picture Picture
    {
      get
      {
        return PictureManager.GetPictureById(this.PictureId);
      }
    }
    #endregion

    #region Navigation Properties

    /// <summary>
    /// Gets the picture
    /// </summary>
    public virtual Picture NpPicture { get; set; }

    /// <summary>
    /// Gets the BlogPost
    /// </summary>
    public virtual BlogPost NpBlogPost { get; set; }

    #endregion

  }
}


The BlogPicture table is a copy of the ProductPicture table.

Can anyone help me out, im really stuck with this problem.
13 年 前
I solved it by deleting the table in the entity chart, and then updating it from the database.. dunno what went wrong.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.