Asked by:
dynamic data - passing entered value to the linq statement

Question
-
User-725790043 posted
Hi, how can i pass the inputted value to the linq statement? here's my code, i want to change "Kiosk" to the value entered in the web page.
partial void OnValidate(System.Data.Linq.ChangeAction action)
{
if (action == System.Data.Linq.ChangeAction.Insert)
{
SMSHotlineDataContext dc = new SMSHotlineDataContext();
var res = from p in dc.Products
where p.ProductName == "Kiosk"
select p;
throw new ValidationException("Product name already exists");
}
}Tuesday, July 29, 2008 12:24 AM
All replies
-
User-330204900 posted
Just refer to the property directly:
partial void OnValidate(System.Data.Linq.ChangeAction action) { if (action == System.Data.Linq.ChangeAction.Insert) { SMSHotlineDataContext dc = new SMSHotlineDataContext(); var res = from p in dc.Products where p.ProductName == this.ProductName select p; throw new ValidationException("Product name already exists"); } }
Hope this helps [:D]Tuesday, July 29, 2008 3:53 AM -
User-330204900 posted
Or alternativly:
public partial class NorthwindDataContext : System.Data.Linq.DataContext { partial void InsertCustomer(Customer instance) { var NWDC = new NorthwindDataContext(); if (NWDC.Customers.SingleOrDefault(c => c.CustomerID == instance.CustomerID) != null) { throw new ValidationException("Duplicate CustoemrID is not allowed"); } else { // finally send this to the DB this.ExecuteDynamicInsert(instance); } } }
Wednesday, July 30, 2008 4:54 AM -
User-725790043 posted
thanks Steve! that did it, one more question though, will this run when i deploy it on .net framework 3.5 (without sp1 beta installed)? [:D]
Thursday, July 31, 2008 10:59 PM -
User-330204900 posted
Well DynamicData required SP1 + the 0718 Runtime from here and from what I here SP1 with the runtime will be out soon. As for the Code above I think that the ValidationException is also apart of Dynamic Data but if you throw a general exception then it will work fine. [:D]
Friday, August 1, 2008 2:05 AM -
User-725790043 posted
thanks, i will have to wait for the SP1 i guess.[:D]Friday, August 1, 2008 2:11 AM -
User-797310475 posted
And you won't have to wait very long :)
Friday, August 1, 2008 2:26 PM -
User-418270074 posted
Is this still "coming soon"? I guess you can't really say anything and there are probably a multitude of different factors affecting this but it'd be useful to have a ball park release date.
I'd be happy if it were in the next few weeks :)
Monday, August 11, 2008 9:08 AM -
User660823006 posted
We released it today. See this post for download links: http://forums.asp.net/t/1303811.aspx.
Monday, August 11, 2008 12:53 PM -
User-418270074 posted
Brilliant thanks, I'd just seen that in my RSS feeds when I got in :) Thats made my day!
Tuesday, August 12, 2008 4:57 AM