LINQ - Query body must end with the select clause or group clause error.

Asked By anamika shah
13-Aug-10 12:24 PM

public static List<IdNamePair> GetModels(string year, string make, string countryCode, string languageCulture)

      {

           

  if (listModel == null)

        {

          listModel = new List<IdNamePair>();

          using (Entities dataContext = new Entities(System.Configuration.ConfigurationManager.ConnectionStrings["Entities"].ConnectionString))

          {

            listModel.AddRange((from veh in dataContext.vwVehicle

                      join model in dataContext.Models on veh.Model equals model.ModelName && model.LanguageCulture == languageculture

 

                      where (string.IsNullOrEmpty(year) || year.IndexOf(veh.Year) >= 0) && (string.IsNullOrEmpty(make) || make.IndexOf(veh.Make) >= 0)

                      && countryCode == veh.countrycode

                      orderby veh.Model

                      select new IdNamePair() { Id = veh.Model, Name = model.ModelLocalized }).Distinct().ToList());

 

                }

 

        return listModel;

      }

I am using list to return model id and model name.List use linq query.

I am joining table model and vwvehicle on veh.Model equals model.ModelName.It works find until that,but when I add model.LanguageCulture equals languageculture.

Model table has LanguageCulture column and I need to compare that is same that parameter languageculture I am passing in the list. I am getting error

As follow

 

Query body must end with the select clause or group clause error.

 

Can anyone help me with the Linq.

Even getting error Even I am getting error Operator && can't be applied to operands of type string  and string  Even getting error Even I am getting error Operator && can't be applied to operands of type string and string

13-Aug-10 12:29 PM

Even I am getting error Operator && can't be applied to operands of type string  and string

  lavanya r replied to anamika shah
31-Aug-10 02:11 PM
i made this changes 

var x = from d in obj.PG_PAYMENT_TRANSACTIONS
                        from a in obj.PG_CONTRACT_MASTER
                        where (d.CREATED_DATE.Date) == (DateTime.Now.Date) && d.CONTRACT_ABBR == a.CONTRACT
                        select new { d.TRANSACTION_ID };
                foreach (var item in x)
                {
                    
                }
now i am getting

The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported
Create New Account
help
LIKE" operator in LINQ to SQL? .NET Framework I am just getting to grips with LINQ to SQL and my first attempt is to create a Search form. I need the LINQ to generate SQL like this: SELECT * FROM CustomerTable WHERE Surname LIKE 'S%' My LINQ so far looks like this: var cons = from c in db.CustomerTable where c.Surname S%' select c; However, it doesn't like "LIKE". How might I mimic this in LINQ? I should add that I'm hardly the world's most experienced C# programmer either! Thanks Edward C# Discussions LINQ (1) IsNullOrEmpty (1) DateTime (1) OP (1) StartsWith (1) IQueryable (1) No, it wouldn't like "LIKE" - you're
write a method? protected void Button1_Click( object sender, EventArgs e) { if (TextBox1.Text = = "" ) { Label1.Text = datetime.now.date.tostring(); } else { Label1.Text = "" + TextBox1.Text; } } which way to write a method in Text); } In the Class File Test.cs using System; using System.Collections.Generic; using System.Linq; using System.Web; / / / <summary> / / / Summary description for Test / / / < / summary> public class Test { public Test() { / / / / TODO Add constructor logic here / / } public string GetText( string tbText) { String OutputText = String.Empty; if (String.IsNullOrEmpty(tbText)) { OutputText = DateTime.Now.Date.ToString(); } else { OutputText = "" + tbText; } return OutputText; } } Hi a small modification in the code Text); } In the Class File Test.cs using System; using System.Collections.Generic; using System.Linq; using System.Web; / / / <summary> / / / Summary description for Test / / / < / summary> public class Test { public Test() { / / / / TODO Add constructor logic here / / } public string GetText( string tbText) { String OutputText = String.Empty; if (String.IsNullOrEmpty(tbText)) { OutputText = DateTime.Now.Date.ToString(); } else { OutputText = "" + tbText; } return OutputText; } } int getYear( DateTime dt) { return dt.Year; } int getYear() { return DateTime .Now.Year; } protected void Button1_Click( object sender
LINQ: How to build dynamic query? .NET Framework Hello, played a little with orcas and went Doing this by building a string is very simple, but how to do it with LINQ? string sql = ""; if (TextBox1.Text ! = "") sql + = "Columns_1 = '"+TextBox1.Text+"'"; if (TextBox2.Text ! = "") sql + = "Columns_2 = '"+TextBox2.Text+"'"; How to include the if query to linq??? var query = from c in db.MyTable where c.Column_1 = = TextBox1.Text && c.Column_2 = = TextBox2 Text select c; Thank you! -Stefan C# Discussions System.Linq.Expressions.Expression.ValidateNewArgs (1) AppDomain.CurrentDomain.AssemblyResolve (1) DBLinq.util.RowEnumeratorCompiler (1) System.Linq.Enumerable.ToList (1) System.IO.File.Delete (1) DBLinq.Linq.MTable (1) DBLinq.util.RowEnumerator (1) System.Reflection.ConstructorInfo (1) Queries are "composable" - hence you things like the following: var query = from s in dataContext.SomeEntities select s; if (!string.IsNullOrEmpty(inputA)) { query = from x in query where x.PropertyA = = inputA select x; } if (!string.IsNullOrEmpty(inputB)) { query = from x in query where x.PropertyB = = inputB select x; } Then enumerate query
use of it? PredicateBuilder.True<> Dynamically Composing Expression Predicates Suppose you want to write a LINQ to SQL or Entity Framework query that implements a keyword-style search. In other words The easiest way to experiment with PredicateBuilder is with LINQPad . LINQPad lets you instantly test LINQ queries against a database or local collection and has direct support for PredicateBuilder (press F4 check 'Include PredicateBuilder'). PredicateBuilder Source Code Here's the complete source: using System; using System.Linq; using System.Linq.Expressions; using System.Collections.Generic; public static class PredicateBuilder { public static Expression<Func<T, bool invokedExpr), expr1.Parameters); } } PredicateBuilder is also shipped as part of LINQKit , a productivity kit for LINQ to SQL and Entity Framework. If you're using LINQ to SQL, you can use the PredicateBuilder source code on its own. If you're class Product { public static Expression<Func<Product, bool> > IsSelling() { return p = > !p.Discontinued && p.LastSale > DateTime.Now.AddDays (-30); } } We can extend this by adding a method that uses PredicateBuilder : public Product, bool> > IsSelling (int minPurchases) { return prod = > !prod.Discontinued && prod. Purchases .Where (purch = > purch.Date > DateTime.Now.AddDays(-30)) .Count() > = minPurchases; } Nesting Predicates Consider the following predicate: p = > p.Price > 100
recently I've used the NoRM C# driver with MongoDb, which implements a very nice LINQ interface over database queries. However, the 10Gen people http: / / www.10gen.com / (who put out the features of MongoDb 1.8. Missing from this driver until recently has been the LINQ support I've come to know and love. However, Craig Wilson has created FluentMongo which implements a fully LINQ - compliant set of extension methods around the AsQueryable extension of the native C# driver's MongoCollection. This makes it possible to execute virtually any MongoDb query via familiar LINQ syntax: _server = MongoServer. Create ( "mongodb: / / localhost" ); _database = _server.GetDatabase( "Cache" ); MongoCollection<CacheItem> coll = _database.GetCollection MongoDB.Driver; namespace MongoCache { [Serializable] public class CacheItem : IMongoQuery { public string Id { get; set; } public DateTime Expires { get; set; } public byte[] Item { get; set; } } } The Id property is the Cache key which MongoDb automatically recognizes as a PK via its name); the Expires property is a DateTime expiry date for the cache item, and the Item property is a byte array that stored. Note also that this implements the IMongoQuery interface which provides us with all the LINQ queryable goodness and access to methods like Save and Remove on a collection. A very have a Helper class that provides some plumbing: using System; using System.Configuration; using System.Linq; using MongoDB.Driver; using MongoDB.Driver.Builders; using FluentMongo; using FluentMongo.Linq; namespace MongoCache { public