views:

105

answers:

2
        List<NastavaIzvjestaj> nastava_izvjestaj = new List<NastavaIzvjestaj>();
        var data_context = new DataEvidencijaDataContext();
        int pomSum = 0;

        var prisustvo = (from j in data_context.nastava_prisustvos 
                select j.br_indexa).Distinct();
        var lista = prisustvo.ToList();

        foreach (var i in prisustvo)
        {
            var pom = from k in data_context.nastava_prisustvos

                      where k.br_indexa == i
                      select k.broj_casova;

            pomSum = pom.Sum();

            nastava_izvjestaj.Add(new NastavaIzvjestaj
            {
                br_indexa = i.br_indexa,
                naziv = "mjau",
                ime = "First Name",
                prezime = "Last Name",
                tip_nastave = "XXX",
                procenat_prisustva =pomSum
            });
        }

            string reportPath = Server.MapPath("NastavaPrikaz.rpt");

            ObjektniNastavaIzvjestaj = new ReportDocument();
            ObjektniNastavaIzvjestaj.Load(reportPath);
            ObjektniNastavaIzvjestaj.SetDataSource(nastava_izvjestaj);
            CrystalReportViewer1.ReportSource = ObjektniNastavaIzvjestaj;

This code return something like this:

           Br_idexa        Ime          Prezime         Procenat

           185             First Name   Last Name           30
           185             First Name   Last Name           30
           185             First Name   Last Name           30
           185             First Name   Last Name           30

How do I get only one row :

           185             First Name   Last Name           30

problem is solved

+1  A: 

Hey,

Try adding a partial class for your NastavaIzvjestaj that does:

namespace ...
public partial class NastavaIzvjestaj
{
   public override bool Equals(object o)
   {
      if (o == null || !(o is NastavaIzvjestaj))
         return false;

      return this.Br_idexa == o.Br_idexa;
   }

   public override int GetHashCode()
   {
      return this.Br_idexa.GetHashCode();
   }
}

Providing that Br_idexa is your unique identifier and pk.

Brian
how I use this in my posted code
Ognjen
Add a new class called NastavaIzvjestaj.cs in the same project as the designer; each LINQ object is a partial class, and the partial keyword allows you to "add-on" to the class definition.The namespace... meant I didn't know what namespace the LINQ to SQL orm was in, and so supply the same namespace there.
Brian
+3  A: 

In your query you can select which column you want to select distinct on:

var prisustvo = (from j in data_context.nastava_prisustvos 
                    select j.br_indexa).Distinct();
Ben Ziegler
I updated code and write new problems
Ognjen