开发者

How to relate entities without navigation property mappings

开发者 https://www.devze.com 2022-12-10 20:48 出处:网络
I Have Database that contains 4 tables TABLE TBLCARTITEM (CART_ID, ITEM_ID, PROMOTION_ID, many more cart item fields)

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

精彩评论

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