hi im not sure whether contains will b ok.To be specific u can use this for like type of queries from a in db.client where SqlMethods.Like(a.Client_Name, "%abc%") select ... sqlmethods have other methods like datwediffday,datediffsecond,datediffhour etc prior writing this include this namespace using System.Data.Linq.SqlClient;
T.Balaji
That's a tough one, because between you checking for uniqueness and you actually inserting your record, somebody else could insert the same record. Ways that this can be achieved would normally be outside the scope of typical LINQ operations. For instance, one way would be to do an insert with the check as part of the condition, e.g. insert into mytable(name) select @name where not exists ....
Deja View - the feeling that you've seen this post before.
My blog | My articles
Firstly.. remember that ASP.NET does not persist the data between creating the page and a postback..you can store variables on a page but they are not persisted on the server.* user requests page -> code is executed -> html returned -> discarded
user clicks button -> code is executed -> html returned -> discarded
Hence there is no point in writing the var query and storing it - this is the wrong approach with ASP.NET. Secondly the query "var query = from s in db.Suppliers select s;" is a query definition, and NOT a result set. LINQ to SQL does not execute a query until you ask it to do something with it, such as bind it to the control(s) or enumerate it. So the answer is "you don't need to" - just write the query in place as needed, e.g. void ShowData(int startRow) { var db = new DataContext(); var query = from s in db.Suppliers skip 0startRow take pageSize select s; this.Gridview1.DataSource = query; } Hope this helps
'Howard
var s = XDocument.Load("rect.xml"); var q = from x in s.Descendants() select new { x }; XNamespace ns = "http://tempuri.org/svg11-flat-20030114"; foreach (var itm in q) { if (itm.x.Name == ns + "rect") { rect re = (rect)itm.x; Console.WriteLine(itm.x.Name.ToString()); } if (itm.x.Name == ns + "desc") { rect re = (rect)itm.x; Console.WriteLine(itm.x.Name.ToString()); } }
I found yet another way @ http://blogs.msdn.com/kaevans/archive/2007/09/03/wcf-and-linq.aspx. "Click on the designer surface in your .dbml file and change the Serialization property to "Unidirectional". That will decorate the generated classes with DataContract and DataMember attributes appropriately."
Perhaps compile that part into a DLL using the command-line compiler? So far I've found that HashSet is the only compelling reason to switch to .net 3.5 (and VS 2008).
The C# equivalent of isnull is the ?? operator. So, you can do the following:
var x = (from a in db.stock
select new { a.stockid }).Distinct();
int c = x.Max(a => a.stockid ?? 0) + 1;
Or, if you want to filter null values in the query:
var x = (from a in db.stock
select new { stockid = (a.stockid ?? 0) }).Distinct();
int c = x.Max(a => a.stockid) + 1;
balaji.t wrote:
Wont it return error "single row subquery returning more than 1 row"? Is there any equivalent keyword like "in"?i mean can we use like this?
No - it won't. Try it and see.
Deja View - the feeling that you've seen this post before.
My blog | My articles
This forum is specifically for new functionality in .NET 3.5, such as LINQ. I recommend you ask this question in the C# programming forum.
Life, family, faith: Give me a visit. From my latest post: "The themes and truths of the Jewish holidays follow God's complete plan for this world. They are the root from which Christianity sprang and the historical reasons the church had for leaving them behind were unsound." Judah Himango
I think it didn't like me changing the names of some properties in the Contact class. I did change it through the designer though, so I have no idea why it's complaining. Well that was a waste of a day and a half. Thanks, Rei
Yep, using LINQ to SQL, you call SubmitChanges on the DataContext.
Life, family, faith: Give me a visit. From my latest post: "We are Christian, resistance is futile. Your Jewish traits will be assimilated into the Church collective." Judah Himango
Why not write a program that uses both and compare?
"The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon