0

I'm trying to figure out a way of mapping an icollection into a table but it throws me this errors:

Error 1:

Cannot implicitly convert type 'System.Collections.Generic.ICollection' to 'elayer.c'. An explicit conversion exists (are you missing a cast?)

Error 2:

Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type EntityLayer

This is part of the code, if needed more for help would love to add, it's driving me crazy,

Mapping.cs

internal class CMapping : EntityTypeConfiguration<c>
{
    internal CMapping()
    {

        this.Property(x => x.Name).HasMaxLength(200);

        this.HasMany(x => x.wc)
            .WithRequired(x => x.c)
            .HasForeignKey(x => x.cid);

    }
}

c.cs

public class c: BaseEntity
{
    public int cid{ get; set; }
    public string Name { get; set; }
    public string Text { get; set; }
    public int link{ get; set; }
    public ctype Type { get; set; }
    public ICollection <wc> wcs{ get; set; }
}

wc.cs

public class wc: BaseEntity
{
    public int wcid { get; set; }
    public int wid{ get; set; }
    public int cid{ get; set; }
    public int BrandId { get; set; }

    public w w{ get; set; }
    public virtual ICollection<c> c{ get; set; }
}

UPDATE ----- wcQueryService

public IEnumerable<wDto> FindwcByStoreIdAndwId(int storeId, int wId)
{
    using (var dc = this._cmsContextFactory())
    {

        var query = from wc in dc.wc
                    join c in dc.c on wc.wId equals c.wId
                    join w in dc.w on wc.wId equals w.wId
                    where wc.IsDeleted == false
                    && c.IsDeleted == false
                    && wc.IsDeleted == false
                    && wc.BrandId == storeId
                    && w.wId == wId
                    select new wDto
                    {
                        wwId = wc.wwId,
                        wId = w.wId,
                        wId = c.wId,
                        BrandId = wc.BrandId,
                        Videos = (from c in wc.w
                                  select new wTypeVideoDto
                                  {
                                      Text = c.Text,
                                      wId = c.wId
                                  }).ToList()
                                         };

        return query.ToList();
    }
}
Saikios
  • 3,623
  • 7
  • 37
  • 51
  • 2
    Oh man you need to name your classes and variables better. What a headache... – rory.ap Mar 18 '16 at 17:14
  • hahaha, it isn't the real names, sorry for that :(, but the would kill me if I post the real names – Saikios Mar 18 '16 at 17:21
  • Alright, why is `c` property in your class `wc` collection? Shouldn't it be `public c c { get; set; }`? – Ivan Stoev Mar 18 '16 at 17:25
  • I tried that, but c on the queryservice I have a collection of c's inside a collection of w (wc is the intermediate) – Saikios Mar 18 '16 at 17:37
  • And when I do that link goes crazy – Saikios Mar 18 '16 at 17:37
  • I added the Query Service, I know it's crazy with the replacements, sorry for that :( – Saikios Mar 18 '16 at 17:41
  • 1
    As I understand, you have `w`, `c` many-to-many via explicit `wc` link table. `wc` should not have collections. `wc` should have single `w` and single `c`, while both `c` and `w` classes should have `ICollection` – Ivan Stoev Mar 18 '16 at 17:46
  • @IvanStoev you are entirely right!, can you post it as an answer so I can check it as an answer? (you saved my sanity :D) – Saikios Mar 18 '16 at 17:53
  • 1
    No worry mate, glad that the problem is solved. feel free to delete the post. cheers. – Ivan Stoev Mar 18 '16 at 18:10

0 Answers0