Posts

Showing posts from September, 2017

Donate

Navigation Properties In Entity Framework Using Database First Approach

Image
Good day! Here's a simple step by step tutorial on exploring the Navigation Properties of EF using the DB approach. According to MSDN , Navigation properties provide a way to navigate an association between two entity types. Every object can have a navigation property for every relationship in which it participates. Navigation properties allow you to navigate and manage relationships in both directions, returning either a reference object (if the multiplicity is either one or zero-or-one) or a collection (if the multiplicity is many). You may also choose to have one-way navigation, in which case you define the navigation property on only one of the types that participates in the relationship and not on both. Given the description, this example demonstrates the concept using two tables Employees and Dependents wherein you search for a particular employee and you can access the related dependents of that employee. To start with, just perform the steps given below. Step 1. Cre

Pivot DataTable Using LINQ In C# And VB.NET

Hello, A question was brought up in the forums on how to Pivot a DataTable object here. The OP has already a solution with reference to this link Cross Tab / Pivot from Data Table . An alternative solution is to utilize the features of LINQ using group by statement to achieve the desired output. This solution consists of few lines of code compared with the solution from the forum post. C# Code var query = ( from students in dt.AsEnumerable() group students by students.Field< string >( "StudID" ) into g select new { StudID = g.Key, Eng = g.Where(c => c.Field< string >( "SubSht" ) == "Eng" ).Sum(c => c.Field< double >( "Score" )), Fre = g.Where(c => c.Field< string >( "SubSht" ) == "Fre" ).Sum(c => c.Field< double >( "Score" )), Mat = g.Where(c => c.Field< string >( "SubSht" ) == "Mat" ).Sum(c => c.Field< double &

Function <Anonymous Method> Doesn't Return A Value On All Code Paths (Action Statement)

Hello, Given the code statement below, the code throws an exception such as anonymous method does not return a value on all code paths. If txtEmployeeHireDate.IsHandleCreated Then If txtEmployeeHireDate.InvokeRequired Then BeginInvoke( New Action(Function() txtEmployeeHireDate.Text = objEmployee.HireDate End Function )) End If End If The code that's inside the BeginInvoke() statement does not necessarily returns a value since I only assigned an object's property value to the textbox control. In order to resolve this, either return a null value or a false value inside the Action delegate. If txtEmployeeHireDate.IsHandleCreated Then If txtEmployeeHireDate.InvokeRequired Then BeginInvoke( New Action(Function() txtEmployeeHireDate.Text = objEmployee.HireDate Return Nothing 'added this statement to fix issue End Function )) End If End If Another solution is to use Sub() which does not return a value instead of Function(

Donate