Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I'm very sorry for my question, I'm new for c# :-(

In This code I recive error message
Error	CS1513	} expected	


I don't know why, in LINQPad 5 is ok, in VS2019 C# doen't work :-(

Why this ?

Thank you for help

var t = (from e in context.T_Att
             group e by new { e.Cod_R, e.Cod_C, e.O_Tot } into g
              select new
                        {
                             Ris = g.Key.Cod_R,
                             Cli = g.Key.Cod_C,
                             O_N = g.Sum(pc => pc.O_Tot) * 1236,
                             O_S = g.Sum(pc => pc.O_Tot).ToString(),
                             Tot_rec = g.Count()
                         }).ToList();


What I have tried:

I have tried many times to change the brackets but to no result.
Posted
Updated 20-May-21 8:11am
Comments
Richard Deeming 20-May-21 10:53am    
Which line does the error point to?

When I dummy up your code in VS 2019:
C#
private void FrmMain_Shown(object sender, EventArgs epp)
    {
    var t = (from e in context.T_Att
             group e by new { e.Cod_R, e.Cod_C, e.O_Tot } into g
             select new
                 {
                 Ris = g.Key.Cod_R,
                 Cli = g.Key.Cod_C,
                 O_N = g.Sum(pc => pc.O_Tot) * 1236,
                 O_S = g.Sum(pc => pc.O_Tot).ToString(),
                 Tot_rec = g.Count()
                 }).ToList();
    }
public class Context
    {
    public List<foo> T_Att { get; set; } = new List<foo>();
    }
public class foo
    {
    public int Cod_R { get; set; }
    public int Cod_C { get; set; }
    public int O_Tot{ get; set; }
    }
public Context context = new Context();
I get no errors: The chances are that the error is referring to code above the fragment you show, and on;y showing up as the first line of that code because it can't work out what you meant to write.

So start by looking at the lines immediately above this: is there a missing "}" or similar?
 
Share this answer
 
Comments
antobaro 20-May-21 14:17pm    
Thank you very much. Your suggestion made me realize the mistake.
I was too focused on the error message about the bracket.
OriginalGriff 21-May-21 1:54am    
You're welcome!
I'm very stupid, without the Using.....
this code never works !!!
Your opinion was very important for me. Thank you very much.


using (var ctx = new RAKEntities())
  {
       var t = (from e in ctx.T_Att
               group e by new { e.Cod_R, e.Cod_C, e.O_Tot } into g
               select new
               {
                   Ris = g.Key.Cod_R,
                   Cli = g.Key.Cod_C,
                   O_N = g.Sum(pc => pc.O_Tot) * 1236,
                   O_S = g.Sum(pc => pc.O_Tot).ToString(),
                   Tot_rec = g.Count()
               }).ToList();
 }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900