I need to sum field depending on 2 tables with 1 to many relations
I have somewhere in my project the following
Dim lqcus = From c In db0.customers Where c.id = txt_idcust.Text Select c
I managed to sum by 2 ways
Dim sum1 = (From s In db0.stocks Where s.CustID = txt_idcust.Text Select c.qty).Sum
Dim sum2 = Aggregate s In db0.stocks Where s.CustID = txt_idcust.Text Into sum(s.qty)
But the above 2 will be executed again in the sql server to get the result, but I already have the lqcus which is linq result for the customer and inside the lqcus there is the stock already filtered by the 1 to many relation
For example, I can write the following
Dim sum3 = From s In lqcus.stocks Where s.CustID = txt_idcust.Text
Open the .dbml file and open properties window.At the top of properties window you can see a dropdownlist.If we select the table name which we want then it would directly navigate to the table in .dbml file
Just getting back into some of the newer stuff from MS. I can't figure out why LINQ to SQL exists. I always thought query's should run in the DB in stored procs and not be in code. Essentually LINQ to SQL is a hard coded SQL Query. I thought this was bad form. What am I missing?
Linq to SQL is a ORM, Object Relational Mapper, tool. It is more than just a way to run queries. It removes the need for the developer to hand create entities, execute queries and map the result sets to those entities. It gives the ability to track changes when objects have been modified. Plus a host of other things. You can still use stored procs with Linq to SQL.
I am working on a C#/.NET application where I need to get Current Identity value of the table using LINQ. Or else I can use the sql query to get the task done by either using var num = DataContext.ExecuteCommand("Select IDENT_CURRENT ('table')");, by using this code, i am getting the value = -1.
var num = DataContext.ExecuteQuery(("Select IDENT_CURRENT ('table')");, by using this code, I am getting an exception "Specified cast is not valid." and the value remains NULL. Correct me if I am doing something wrong. let me know if there are any better ways to do this task.
my scenario is different where Last few records in the table are deleted.............So in that scenario i will not be getting the right value needed.
presently 30 records --> Max(id) gives me 30
4 records added to the table---> Max(id) gives me 34
Now i am deleting the last 4 records added this means that Current Identity value will be 34 but when i do Max(id) it gives me 30 but the correct value is 34.right?
Thanks for ur help in advance.
Last Visit: 31-Dec-99 18:00 Last Update: 24-Jul-17 21:52