开发者

How to relate entities without navigation property mappings

I Have Database that contains 4 tables

 TABLE TBLCARTITEM (CART_ID, ITEM_ID, PROMOTION_ID, many more cart item fields)
 TABLE XREFCARTITEMPROMOTION (CART_ID, ITEM_ID, PROMOTION_ID)
 TABLE TBLPROMOTION (PROMOTION_ID, PROMOTION_TYPE_ID, many more promotion fields)
 TABLE LKPROMOTIONTYPE (PROMOTION_TYPE_ID, PROMOTION_TYPE_DESCRIPTION)

The XREFCARTIEMPROMOTION table is a cross reference table that creates开发者_JAVA百科 a many-to-many relationship between TBLCARTITEM and TBLPROMOTION.

TBLPROMOTION is linked to LKPROMOTIONTYPE by PROMOTION TYPE ID.

I am trying to use LINQ to get all of a particular carts items and related promotions.

So far i have everything with the exception of the LKPROMOTIONTYPE table.

using (WSE db = new WSE())
{ 
   var cartItems = db.XREFCARTITEM.Include("TBLPROMOTION")
           .FirstOrDefault(x => x.CART_ID == cartId);
}

This gives me everything for the cart including the promotions tied to each item. However when i go and try to include the LKPROMOTIONTYPE table i get the following run-time error:

A specified Include path is not valid. The EntityType 'Model.XREFCARTITEM' does not declare a navigation property with the name 'LKPROMOTIONTYPE'.

My question is: Does anyone know of a way to relate LKPROMOTIONTYPE to this cartItems object above?

Thanks.


Answered my own question this time:

var cartItems = db.XREFCARTITEM
                  .Include("TBLPROMOTION.LKPROMOTIONTYPE")
                  .FirstorDefault(x => x.Cart_ID == cardId);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜