views:

69

answers:

1

I try to give entity map on my entity app. But how can I do it? I try to make it like below:

var test = ( from k in Kartlar where k.Rehber.....

above codes k.(can not see Rehber or not working ) if you are correct , i can write k.Rehber.ID and others. i can not write:

from
 k in
 Kartlar
where
k.Rehber.ID = 123 //assuming that navigation property name is Rehbar and its primary key of Rehbar table is ID
&& k.Kampanya.ID = 345 //assuming that navigation property name is Kampanya and its primary             //key of Kampanya table is ID
&& k.Birim.ID = 567 //assuming that navigation property name is Birim and its primary key of Birim table is ID
select
k

images you can see: alt text

also: You should look : http://i42.tinypic.com/2nqyyc6.png

I have a table it includes 3 foreign key field like that:

My Table: Kartlar

  • ID (Pkey)
  • RehberID (Fkey)
  • KampanyaID (Fkey)
  • BrimID (Fkey)
  • Name
  • Detail

How can i write entity query with LINQ ?

select * from Kartlar where RehberID=123 and KampanyaID=345 and BrimID=567

BUT please be careful I can not see RehberID, KampanyaID, BrimID in entity they are foreign key. I should use entity key but how?

A: 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;
using System.Data.Objects;
using System.Data.Objects.DataClasses;
using System.Web.UI.MobileControls;

namespace EfEntity
{
public partial class _Default : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
gwKampanya.DataSource = Kart(297688, 88689, 68686);
gwKampanya.DataBind(); } }

    public List<Kartlar> Kart(int RehberID, int KampanyaID, int BrimID)
    {
        List<Kartlar> kartlar;
        using (xyzEntities genSatisctx = new xyzEntities())
        {
            kartlar = (from k in genSatisctx.Kartlar
                       where k.Rehber.ID == RehberID &&
                             k.Kampanya.ID == KampanyaID &&
                             k.Birim.ID == BrimID
                       select k).ToList();

            return kartlar;

        }
    }
}

}

programmerist