As I am new to Linq and Entity Framework, I don't know how I add comma sepearted and left join in linq/Entity code. My Sql query is rather big and I want it to be convert in Linq/entity: Select DISTINCT SR.StudentRequestId,SR.RegistrationId,SR.Location,SR.PaymentMethod,SR.CreatedOn,C.ClassName,CC.CampusName, CASE WHEN ISNULL(TSR.StatusId,0)=0 THEN 1 ELSE TSR.StatusId END AS StatusId, substring( ( Select ', '+REPLACE(REPLACE(ST1.FromTime,'AM',''),'PM','')+'-'+ST1.ToTime AS [text()] From dbo.StudentRequestTimings ST1 Where ST1.StudentRequestId = SRT.StudentRequestId ORDER BY ST1.CreatedOn For XML PATH ('') ), 2, 1000) [Time] FROM StudentRequest SR Inner JOIN Registration R ON R.RegistrationId=SR.RegistrationId INNER JOIN Campus CC ON CC.CampusId=R.CampusId INNER JOIN Class C ON C.ClassId=SR.ClassId LEFT JOIN TutorClasses …

Member Avatar
Member Avatar
+0 forum 1

I have a `List<double> MyList` something looking like this: 4.75/1.01/5.66/NaN/42.42/3.33 I’d like to get the minimum value of 1.01 out of it, but I get d = NaN when doing `double d = MyList.Min();` Tried, after some long internet strolls, something with LINQ to no avail. Some LINQ afictionados around here, who can help me out? As always, my gratitude will be immense.

Member Avatar
Member Avatar
+0 forum 3

Hi all I'm new using LinQ. Im having Specified Cast not Valid in this Function. Hope someone let me know what I'm doing wrong. this is the Function Private Function GroupedBy() As DataTable Dim Sales As New ds_Sales_OELI Dim dt As DataTable = Sales.Not_SCheduled GroupedBy = New DataTable Dim dr As DataRow With GroupedBy .Columns.Add("ProDate", GetType(String)) .Columns.Add("ttlCabs", GetType(Integer)) End With Dim ReadyProduction As IEnumerable(Of DataRow) = dt.AsEnumerable Try Dim QUERY = From InPro In dt.AsEnumerable Group InPro By production = InPro.Field(Of String)("inProduction") Into G = Group Select New With { .category = production, .cab1 = G.Sum(Function(inpro) inpro.Field(Of Integer)("CabCat1")), .cab2 = …

Member Avatar
Member Avatar
+0 forum 3

I'm using linq on a array and I need to find the index of the linq result. Is this possible? how? My thanks in advanced. This is my code: Vector3[] vertices=mesh.vertices; var V3=(from cur in vertices where (cur.x==point.PointX) && (cur.y==point.PointY) select cur).FirstOrDefault();

Member Avatar
Member Avatar
+0 forum 1

I have a linq statement where i turned letter grades into numbers to calculate a gpa can anyone tell me why no matter what grade i click i get the same gpa of 68 for each one? maybe someone can look over my code and give me an answer or hint thanks Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles btnDisplay.Click Dim dic As Dictionary(Of String, Integer) = New Dictionary(Of String, Integer) dic.Add("A", 4) dic.Add("B", 3) dic.Add("C", 2) dic.Add("D", 1) dic.Add("F", 0) Dim gpa = Aggregate Grade In CoursesDataSet.tblCourses.AsEnumerable() Select Grade.Field(Of Integer)("CreditHours") * dic(Grade.Field(Of String)("Grade")) Into Sum() MessageBox.Show("GPa:" & …

Member Avatar
Member Avatar
+0 forum 3

need to code a linq statement that codes the grade display button so it allows the user to display either all records or only records matching a specific grade. Also it has to calculate a gpa where a=4 b=3 c=2 d=1 f=0 My main problem is with a linq statement how do i define grade into an integer? This is what I have tried so far: Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles btnDisplay.Click Dim GPA As Integer = Aggregate CreditHours In CoursesDataSet.tblCourses Select CreditHours * Grade Into sum() MessageBox.Show("GPa:" & GPA.ToString("C2"), "College Courses", MessageBoxButtons.OK, MessageBoxIcon.Information) End Sub …

Member Avatar
Member Avatar
+0 forum 1

# Performing Selective Includes in Entity Framework with the Fluent API # When we are using Entity Framework as our data access choice to work with SQL Server then there are some potential pitfalls. One of these pitfalls is doing selective includes. What do I mean by selective includes? To answer that let's first look at our class and database model. Lets suppose we have some customers and some invoices in our application. Our database schema and model classes could look like this: ![schema.png](/attachments/large/2/3ddde68520a7f7732b4b56cb8ef47c59.png "align-center") And we may have data like this: ![data.png](/attachments/large/2/1112ce0ee2ae9e0e575964c99e8e3e41.png "align-center") Now suppose we wanted to select …

Member Avatar
+1 forum 0

I have this Linq expression that works well. What is the right approach to test if it has returned anything? internal static void getCreditNotes(string invoiceId, out DataTable creditNotes,out double total) { total = 0; creditNotes = new DataTable(); var q = dt.AsEnumerable(). Where(r => (string) r["invoiceId"] == invoiceId && (string) r["TransactionType"] == "CreditMemo"); creditNotes = q.CopyToDataTable(); total = creditNotes.AsEnumerable().Sum(r => (double) r["TransactionAmount"]); This code breaks on line 9 (q.CopyToDataTables) when there are no rows. I could use a try catch but that seems a bit of an overkill.

Member Avatar
Member Avatar
+0 forum 4

Hi, having code placed below, I cannot clue out, how to convert query in FilterData() to a dynamic query. Any ideas how to do it? Thanks in advance for any hint. Martin public class Item { public DateTime SampleDate; public List<String> Columns = new List<String>(); //this stores all columns } public class ItemList : List<Item> { public void GetDataFromFile() { //hier I read data line by line from a file, and split each line to get column foreach(var row in "rows read from a file") { Item myRow = new Item(); myRow.SampleDate = "data column read from a file"; foreach(var …

Member Avatar
Member Avatar
+0 forum 4

I am doing ex4 from the fundamentals of C#. But I cannot solve the problem. I am unable to slice the array correctly and instead just endup with System.int32[] Simply all I am supposed to do is find the maxmimal sequence of equal consecutive elements. I am trying to follow the methodology they are using in the chapter. using System; using System.Collections.Generic; using System.Linq; class ArrayEx4 { static void Main() { int[] testArray = { 1, 1, 2, 3, 2, 2, 2, 1 }; // Output wanted {2,2,2}; int count = 0; int bestCount = 0; int startArray = 0; …

Member Avatar
Member Avatar
+0 forum 6

What is the best way to get the object, within a list of that object type, that has the highest ID number? I've been trying to figure it out and I can manage to get the highest ID number but not the object containing that ID number. Any help would be massivly appreciated, Thanks.

Member Avatar
Member Avatar
+0 forum 7

**I have a table with 4 columns = a(ID),b,c and d.By using LINQ, how can I calculate 'd'* 'b' / 'c' while changing 'a' with a combobox?And would it make any difference if it is a VIEW? is it a fair question? and do you need more information? **

Member Avatar
Member Avatar
+0 forum 1

Hi, Could someone please help me to optimize the attached code file. as i'm new to c# world. Thanks in advance cheers

Member Avatar
Member Avatar
+0 forum 1

I have 2 below tables: tblCustomers: id customerName 1 John 2 Philip 3 Steve tblOredrs: id customerId ordId payment 1 1 100 True 2 1 101 True 3 1 102 False 4 2 101 True 5 2 102 True 6 2 103 False 7 3 101 True my condition is: where (orderId = 101 and orderId = 102) I want to see all payment true order, for the customers that have orders (101 & 102). but orderids may be more than 2, it must be dynamic. i must get: john 100 john 101 Philip 101 Philip 102

Member Avatar
Member Avatar
+0 forum 6

i have follwing data in datatable how to convert it to xml ErrorType UtilityType MstLocCode MDescription SubLocCode SDescription FieldName FDescription 1 Elect NM0001 XMN001 ABC ddsafs 1 Elect NM0001 XMN001 XYZ ddsafs 1 Elect NM0001 XMN001 LMN ddsafs 1 Elect NM0005 XMN002 sds 1 Elect NM0006 XMN002 fghfgh Gas ddsafs 1 Elect NM0002 asas 1 Elect NM0003 asas 1 Alect NM0004 asas 2 Alect NM0008 asas and my xml output will be like follwoing <Country Code=“Test”> <Error Type=“1”> <Utility Name=“Elect”> <MSTLOC Code=“NM0001” > <SubLocation Code=“XMN001”> <Field Name=“ABC” ErrorMessage=“ddsafs”/> <Field Name=“XYZ” ErrorMessage=“ddsafs”/> <Field Name=“LMN” ErrorMessage=“ddsafs”/> </SubLocation> </MSTLOC> <MSTLOC Code=“NM0005” > <SubLocation …

Member Avatar
+0 forum 0

Hi, i have these codes: Dim dt3 As New DataTable dt3.Columns.Add("AdminNo", GetType(String)) '/*Add column AdminNo dt3.Columns.Add("PaperNo", GetType(Integer)) Dim curmodule As String = String.Empty For Each dr1 As DataRow In dt1.Rows curmodule = dr1("ModuleCode").ToString For Each dr2 As DataRow In dt2.Rows Dim found As Boolean found = False For i As Integer = 0 To dt2.Columns.Count - 1 If curmodule = dr2(i).ToString Then found = True Dim dr3 As DataRow dr3 = dt3.NewRow dr3("AdminNo") = dr1("AdminNo") dr3("PaperNo") = dr2("PaperNo") dt3.Rows.Add(dr3) 'DataGridView3.AutoGenerateColumns = True 'Me.DataGridView3.DataSource = dt3 End If Next Next Next Dim dt As New DataTable '' Create 3 typed columns …

Member Avatar
Member Avatar
+0 forum 2

Hi All, I'm fairly new to using Linq but I thought I had a handle on it, apparently not though. I'm processing an XML file sent out as an error report by a third party. I have no control over this file and it has been developed to an industry standard so I can not get the format changed even if I want to. Anyway here is a "cut down" sample of the file, sorry about the size but I've only put things I need to query on.: <?xml version="1.0" encoding="UTF-8"?> <Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.002.001.03" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <CstmrPmtStsRpt> <GrpHdr> <!-- I dont use …

Member Avatar
Member Avatar
+0 forum 4

Could one be preferred over the other in terms of performance? Both option have to traverse the whole array somehow to find out which string contains an 'a'. Or does it not matter much and is it just a syntax thing. Or are there better ways to do this? All your opinions are greatly appriciated. Here's the code. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; namespace ConsoleApplication10 { class Program { static void Main(string[] args) { string[] fruits = { "prune", "apple", "pear", "banana", "cherry", "orange", "blueberry" }; Console.WriteLine(" --- Option1 use of LINQ"); Option1(fruits); Console.WriteLine(" --- …

Member Avatar
Member Avatar
+0 forum 3

Hello my fellow Daniwebies! I have a curious, possibly unique, and odd problem for everyone! We support an ASP.NET application which is using VB.NET for code behind. We use LINQ to SQL and classed object for the data retreival. I have an object called...myObject which is being deleted: Public Shared Sub Delete(ByVal moIn As myObject) Try Dim db As New DataBaseDataContext() db.myTable.Attach(myObject) db.myTable.DeleteOnSubmit(myObject) db.SubmitChanges() db = Nothing Catch ex As Exception Throw ex 'Exception is handled on front end End End Sub The code fires successfully and the object is 'deleted'. Here is the odd thing: When checking from SQL …

Member Avatar
Member Avatar
+0 forum 2

Hello, I am trying to create an outer join in Linq using DefaultIfEmpty. It does not seem to be working. Basically I want c.TotalAmount to be 0 if it does not exist in the second/right table. Any ideas as to what I might be doing wrong? The query does execute, but it seems to still work as an innner join. I do not get any results where the join fails. Thanks very much. var rtaloBySystem = (from r in RTLO from c in contractCoverageBySystem.DefaultIfEmpty() where r.System_ID == c.System_ID && r.Month == c.Month && r.Year == c.Year select new Allocator() {Month …

Member Avatar
Member Avatar
+0 forum 1

Hello folks, I'm currently studying how to use LinQ in VB.NET but I guess I'm stock. I'm using VS 2008 version (framework) 2.0 Anyone who can help me get through this??

Member Avatar
Member Avatar
+0 forum 11

Hi, I am attempting to replace the database in an application with MariaDB. This application is written in C# and previously accessed the database (mostly inserts) with LINQ. When I attempt to insert (other transactions have the same type of issue) I get the error message: "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '[t0].[Id], [t0].[BirthYear], [t0].[FirstName], [t0].[Gender], [t0].[LastName], [' at line 1" The table in MariaDB is setup the same as it was in MS SQL. Any thoughts on this subject would …

Member Avatar
Member Avatar
+0 forum 6

Hi, I have two LINQ queries that produce two different results, but the fields, while having different names, are essentially the same. I am trying to union them together (although concat in this case should produce the same results), but I am getting an error. My thought is that I somehow need to declare the type of the resulting fields, but I am not sure how to do that and if it is correct. Could anyone guide me down the right path to figure out what is wrong? Thanks very much. I have the code and the error below. var …

Member Avatar
Member Avatar
+0 forum 7

So I have this linq code and I am trying to get it to look at the datbase and what it is doing is pulling back the last record put into the database. My asp page refreshes and displays the new information that was updated. What I want is to have it so when a row has not been updated in 5 minutes that it turns the textbox red. I know how to do the change the textbox but I do not know how to search if a row was updated in the last 5 minutes or not. I do …

Member Avatar
Member Avatar
+0 forum 3

good morning guys, i'm developing a website. whereby have to move through records..next and previous...i did something like this public Product NextProduct(List<Product> products, Product product) { Product nextproduct = (Product)product; for (int i = 0; i < products.Count; i++) { if (Equals(products[i].ProductId, product.ProductId)) { if (products[i + 1].ProductId == null) { return null; } else { nextproduct = products[i + 1]; } } } return nextproduct; } public Product PrevProduct(List<Product> products, Product product) { Product prevproduct = (Product)product; for (int i = 0; i < products.Count; i++) { if (Equals(products[i].ProductId, product.ProductId)) { if (products[i - 1].ProductId == null) { return …

Member Avatar
Member Avatar
+0 forum 3

Ok so I'm a total noob with VB.NET and I so far I've read about a thousand forums and I've yet to get a straight answer. I've read that VB treats anonymous types differently than C# (the why, beats me). I have a DataTable, and I want to return a NEW Table with the **duplicate entries** (of columns 4 and 5) from the first one. For ex: T1 looks like this: [COL4][COL5][COL6]...[COLN] 1 1 1 2 1 1 1 3 1 3 The Output Table should be like this: [COL4] [COL5] 1 1 1 3 So far I've got this: …

Member Avatar
Member Avatar
+0 forum 3

Can anyone help me. My code is not working this is cascading drop down list. It's connected to my database. Jquery Code: <script type="text/javascript"> $(document).ready(function () { $("#SiteId").change(function () { var idDept = $(this).val(); $.getJSON("Service/GetBuildingNameList", { id: idDept }, function (myData) { var select = $("#BuildingID"); select.empty(); $.each(myData, function (index, itemData) { select.append($('<option/>', { value: itemData.Value, text: itemData.Text })); }); }); }); }); </script> @Html.DropDownListFor(model => model.SiteId, new SelectList(ViewBag.ListSiteClass as System.Collections.IEnumerable, "SiteId", "SiteName"), "", new { id = "SiteId" }) @Html.DropDownListFor(model => model.BuildingId, new SelectList(Enumerable.Empty<SelectListItem>(), "BuildingID", "BuildingName"), "", new { id = "BuildingID" }) Controller Code: [AcceptVerbs(HttpVerbs.Get)] public JsonResult GetBuildingNameList(int …

Member Avatar
Member Avatar
+0 forum 3

Hi Guys.. Hoping you can help here.. I'm dabbling with Linq as I'm wanting to pass a Node Value from the XML file into the Connection String. Currently my Code seems to be working and holding the Value in the System.(Code Below:)(Screenshot attached also) XDocument testXML = XDocument.Load("C:\\twDB.xml"); var DataBases = from DataBase in testXML.Descendants("DataBase") select new { Connection = DataBase.Element("Connection").Value.ToString() }; I placed a textbox1 onto my form just to make sure I could pass the value but i'm not able too? Any help on this would be great. Regards Mark.

Member Avatar
Member Avatar
+0 forum 1

Hey everyone, so I have this project for windows phone i have to do and I have to put some pins on a bing map, but in order to do that I make an API request to google for google places. I get back an XML file and it's like this <?xml version="1.0" encoding="UTF-8"?> <PlaceSearchResponse> <status>OK</status> <result> <name>Tetsuya's</name> <type>restaurant</type> <type>food</type> <type>establishment</type> <formatted_address>529 Kent Street, Sydney NSW, Australia</formatted_address> <geometry> <location> <lat>-33.8750460</lat> <lng>151.2052720</lng> </location> </geometry> <rating>4.3</rating> <icon>http://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png</icon> <reference>CnRmAAAANRC46osWIWF63JgsOdM2XGk22I0x4HxtfL9F_XWMmF3s-ayUyIwvnySqckNlMreu53OqSrX3YsffYOxQh7PYKV2KzI19EqVcBe50qBwmy_vSXoJ3L6ehFYDJTvpHhwAH3b4BFwM8spTOwjOSMeTqhhIQ3LhryZnC4k2F7nKkT9f-8RoUVBwA9UV-C8hHNZh44YkvVOxxtK0</reference> <id>827f1ac561d72ec25897df088199315f7cbbc8ed</id> </result> <result> <name>Quay</name> <type>cafe</type> <type>bar</type> <type>restaurant</type> <type>food</type> <type>establishment</type> <formatted_address>Upper Level, Overseas Passenger Terminal/5 Hickson Road, The Rocks NSW, Australia</formatted_address> <geometry> <location> <lat>-33.8583790</lat> <lng>151.2100270</lng> …

Member Avatar
Member Avatar
+0 forum 5

My linq query won't insert my data. What am I doing wrong? class Query { musicEntities db = new musicEntities(); public bool findArtist(string artist) { bool status = db.Artists.Any(w => w.Name.Contains(artist)); return status; } public void insertArtist(string artist) { if (findArtist(artist) == false) { Artist art = new Artist { Name = artist }; db.Artists.AddObject(art); db.SaveChanges(); } } }

Member Avatar
Member Avatar
+0 forum 4

The End.