Posts

LINQ: Showing Single Record From Child Table with Parent Table Row.

In LINQ if you want to show the child table single record with the parent table, you can do like below: from mem in ctx.Member join ord in ctx.MemOrder on mem.member_id equals ord.member_id into memord select new StagingClass {  mem.member_id,  latestOrderNo = memord.FirstOrDefault().OrderNo }

Silverlight: Simple way to create call back method.

The Simple way to create a call back method in .Net. also you can pass on the value to the callback object inside the another call backmethod to your callbackmethod. Private Guid userId; public void SaveAndComplete(bool complete, Action onComplete) { userId= //One more callback method. _dc.SubmitChanges(SaveCompleted, onComplete); } private void SaveCompleted(SubmitOperation so) { if (!so.HasError) { //this is where you can pass on the value to the call back method. ((Action)so.UserState)(UserId); } else { //Error message } } Calling the callback method "SaveAndComplete" private void Save_Click(object sender, RoutedEventArgs e) { SaveAndComplete(false, SavedSuccessFully); } private void SavedSuccessFully(Guid generatedID) { //here you will get the value which you hve passed from the callback method. if (generatedAssessmentID == Guid.Empty) return; }

Silverlight: Finding Parent control

The problem the UserControl's parent is not the ChildWindow, its the Grid inside the child window. You need to get the parent of the parent of the UserControl to navigate to the ChildWindow:- ChildWindow cw = (ChildWindow)((FrameworkElement)this.Parent).Parent; However embedding this in your UserControl would bad practice, you would be stipulating to the consumer of your UserControl where the it can be sited. In the above case for the user control to work it would need to always be a direct child of the Layout root. A better approach would be to search up the visual tree looing for a ChildWindow. I would use this helper method (actually I'd place this in a helper extensions static class but I'll keep it simple here). private IEnumerable Ancestors() { DependencyObject current = VisualTreeHelper.GetParent(this); while (current != null) { yield return current; current = VisualTreeHelper.GetParent(current); } } Now you can use LINQ methods to get the...

Silverlight: Normal Properties vs. Dependency Properties

In the Silverlight development world there are two kinds of properties that you can have on a Silverlight control: normal C# properties and dependency properties. The normal C# properties are added to a Silverlight control the same way as they would be added to any C# class: public string MyProperty { get; set; } And then in XAML, you could set the value of the property like this: <MyControl MyProperty= "someValue" /> This works fine for setting specific values in templates that are unlikely to change or if they do change then the change is always manually made to the XAML file. But what happens if you want to have the value of the property bound to some other value that is retrieved from a database, web service, etc? You might try Binding to the property like so: <MyControl MyProperty= "{Binding DynamicPropertyValue}" /> Where DynamicPropertyValue was a property on the parent element that you wanted to to have your pro...

SQL: Getting rownumber

Suppose you have List of record from a table and you need the rownumber for each row you can use this below query: row_number() OVER (ORDER BY [Project2].[case_no] ASC) AS [row_number]

SQL: Conditional Where Clause

If you have some scenario where you need to add where clause based on some condition. for example: GradeID     MinMark   MaxMark    Grade 1           0          0          A 2           0          10         B 3           11         20         C 4           21         NULL       D As per above table we need Grade based on parameter @Mark to be checked as per the ...

IIS: Make Your site work with https on local IIS.

To make your site work on the https you need to follow some steps: Open the IIS Select the local Server on left side Tree(rootnode) Now on right hand side area Double Click on Server Certificates After that on right hand side panel select the Create Self Signed Certificate. Remeber this certificate is not a trusted certificate. That will open an dialog and give a friendly name and then click OK. Now on the left panel tree navigate to the Default Web Site or the website and select it,which you want to run on https. Now on the right hand side panel click on Binding that will open a dialog. Click the Add button will open another dialog in that dialog you need to slect the type "https". Then select the certificate you created ob the step 4 and 5 and click OK. Now you can brows your localhost with https as https://localhost/ Now enjoy using https in your local environment to test the application.