AWK - weird difference between printf and sprintf when taking substr - unix

it's been a while since I have used AWK, but now i have an XML file where I like to increase an Id for a specific column; so it's an excellent task for AWK.
In theory, to increase the Id, the line gets parsed, you fish out the Id into a variable, ++ it, and reconstruct the line to print to the resulting stream.
However, when I use the variable ( x = sprintf(...)) I got weird results, so I used printf to debug the thing. And now the weird part : printf dumps exactly the right Id, but the variable gets rubbish, although they have the same input & syntax ...
Must be somethinig really silly off course, but I can't put my finger on it.
All Ids are in the form :
<column name="Id" type="System.Int32">x</column>
This is the code :
#!/bin/ksh
cd /mnt/c/J/D/Work/GIT/Repos/SkillsNG/SkillsNG.WebTests/Snapshots
print -n "Snapshot name: "
read snapshot
defaultId=0
print -n "Start increasing from Id [$defaultId]":
read id
[[ "$id" = '' ]] && id=$defaultId
cat $snapshot | awk -F '>' 'BEGIN {process=0;} {
if (match($0, /SecurityPermissions/))
{process=1;}
else
{
if (!process)
{
# just dump all tables up to SecurityPermissions, no processing needed
print;
next;
}
}
if (match($1, /<column name="Id" type="System.Int32"/))
{
if(match($2,/[0-9]*/))
{
printf "param 1: %s\n", $1
printf "param 2: %s\n", $2
printf "Id value : %s\n", substr($2, 1, index($2,"\<")-1);
val = sprintf("%s", substr($2,1, index($2,"\<")-1));
printf "value in variable: %s\n", $val;
newval = strtonum(val);
printf "new: %s\n", $newval
}
}
else print $0;
}' > $snapshot.new
# mv $snapshot $snapshot.old
# mv $snapshot.new $snapshot
cd -
And this a simple test xml:
<snapshot culture="en-US">
<table name="[dbo].[SecurityPermissions]">
<row>
<column name="Id" type="System.Int32">1</column>
<column name="GroupId" type="System.Int32">1</column>
<column name="Securable" type="System.Int32">1</column>
<column name="Access" type="System.Int32">1</column>
</row>
<row>
<column name="Id" type="System.Int32">2</column>
<column name="GroupId" type="System.Int32">1</column>
<column name="Securable" type="System.Int32">50</column>
<column name="Access" type="System.Int32">1</column>
</row>
<row>
<column name="Id" type="System.Int32">3</column>
<column name="GroupId" type="System.Int32">1</column>
<column name="Securable" type="System.Int32">51</column>
<column name="Access" type="System.Int32">15</column>
</row>
<row>
<column name="Id" type="System.Int32">4</column>
<column name="GroupId" type="System.Int32">1</column>
<column name="Securable" type="System.Int32">52</column>
<column name="Access" type="System.Int32">3</column>
</row>
<row>
<column name="Id" type="System.Int32">5</column>
<column name="GroupId" type="System.Int32">1</column>
<column name="Securable" type="System.Int32">53</column>
<column name="Access" type="System.Int32">1</column>
</row>
<row>
<column name="Id" type="System.Int32">6</column>
<column name="GroupId" type="System.Int32">1</column>
<column name="Securable" type="System.Int32">54</column>
<column name="Access" type="System.Int32">3</column>
</row>
<row>
<column name="Id" type="System.Int32">7</column>
<column name="GroupId" type="System.Int32">1</column>
<column name="Securable" type="System.Int32">56</column>
<column name="Access" type="System.Int32">1</column>
</row>
<row>
<column name="Id" type="System.Int32">8</column>
<column name="GroupId" type="System.Int32">1</column>
<column name="Securable" type="System.Int32">57</column>
<column name="Access" type="System.Int32">3</column>
</row>
<row>
<column name="Id" type="System.Int32">9</column>
<column name="GroupId" type="System.Int32">1</column>
<column name="Securable" type="System.Int32">77</column>
<column name="Access" type="System.Int32">15</column>
</row>
<row>
<column name="Id" type="System.Int32">10</column>
<column name="GroupId" type="System.Int32">1</column>
<column name="Securable" type="System.Int32">78</column>
<column name="Access" type="System.Int32">15</column>
</row>
<row>
<column name="Id" type="System.Int32">11</column>
<column name="GroupId" type="System.Int32">1</column>
<column name="Securable" type="System.Int32">80</column>
<column name="Access" type="System.Int32">15</column>
</row>
</table>
</snapshot>
Result file :
<snapshot culture="en-US">
<table name="[dbo].[SecurityPermissions]">
<row>
param 1: <column name="Id" type="System.Int32"
param 2: 1</column
Id value : 1
value in variable: <column name="Id" type="System.Int32"
new: <column name="Id" type="System.Int32"
<column name="GroupId" type="System.Int32">1</column>
<column name="Securable" type="System.Int32">1</column>
<column name="Access" type="System.Int32">1</column>
</row>
<row>
param 1: <column name="Id" type="System.Int32"
param 2: 2</column
Id value : 2
value in variable: 2</column
new: 2</column
<column name="GroupId" type="System.Int32">1</column>
<column name="Securable" type="System.Int32">50</column>
<column name="Access" type="System.Int32">1</column>
</row>
<row>
param 1: <column name="Id" type="System.Int32"
param 2: 3</column
Id value : 3
value in variable:
new:
<column name="GroupId" type="System.Int32">1</column>
<column name="Securable" type="System.Int32">51</column>
<column name="Access" type="System.Int32">15</column>
</row>
<row>
param 1: <column name="Id" type="System.Int32"
param 2: 4</column
Id value : 4
value in variable:
new:
<column name="GroupId" type="System.Int32">1</column>
<column name="Securable" type="System.Int32">52</column>
<column name="Access" type="System.Int32">3</column>
</row>
<row>
param 1: <column name="Id" type="System.Int32"
param 2: 5</column
Id value : 5
value in variable:
new:
<column name="GroupId" type="System.Int32">1</column>
<column name="Securable" type="System.Int32">53</column>
<column name="Access" type="System.Int32">1</column>
</row>
<row>
param 1: <column name="Id" type="System.Int32"
param 2: 6</column
Id value : 6
value in variable:
new:
<column name="GroupId" type="System.Int32">1</column>
<column name="Securable" type="System.Int32">54</column>
<column name="Access" type="System.Int32">3</column>
</row>
<row>
param 1: <column name="Id" type="System.Int32"
param 2: 7</column
Id value : 7
value in variable:
new:
<column name="GroupId" type="System.Int32">1</column>
<column name="Securable" type="System.Int32">56</column>
<column name="Access" type="System.Int32">1</column>
</row>
<row>
param 1: <column name="Id" type="System.Int32"
param 2: 8</column
Id value : 8
value in variable:
new:
<column name="GroupId" type="System.Int32">1</column>
<column name="Securable" type="System.Int32">57</column>
<column name="Access" type="System.Int32">3</column>
</row>
<row>
param 1: <column name="Id" type="System.Int32"
param 2: 9</column
Id value : 9
value in variable:
new:
<column name="GroupId" type="System.Int32">1</column>
<column name="Securable" type="System.Int32">77</column>
<column name="Access" type="System.Int32">15</column>
</row>
<row>
param 1: <column name="Id" type="System.Int32"
param 2: 10</column
Id value : 10
value in variable:
new:
<column name="GroupId" type="System.Int32">1</column>
<column name="Securable" type="System.Int32">78</column>
<column name="Access" type="System.Int32">15</column>
</row>
<row>
param 1: <column name="Id" type="System.Int32"
param 2: 11</column
Id value : 11
value in variable:
new:
<column name="GroupId" type="System.Int32">1</column>
<column name="Securable" type="System.Int32">80</column>
<column name="Access" type="System.Int32">15</column>
</row>
</table>
</snapshot>
As can be seen from the result file, the Id value (via printf) works correctly, but the same construct to a variable (via sprintf) produces garbage.
Anybody got an idea what is going on?
Thanks in advance.
Cheers,
DJ

First of all, you should not try to do these things with awk or sed or anything like that. XML is a complicated data-structure with all its ugliness connected to it. While a simple awk might do it now, it will fail all of a sudden and you will not know what hit you.
If you want to increment that particular value, you could use the following xmlstarlet command:
$ xmlstarlet ed --update '//table/row/column[#name="Id"]' -x ".+1" test.xml
It reads like this: xmlstarlet will (ed) edit the file test.xml by (--update) updating all nodes that match the XPath expression ('//table/row/column[#name="Id"]' :: all nodes column child of row child of of table with an attribute name equal to Id) and change its value with an XPath expression -x ".+1" (increment current value (.))
To answer your question: you obtain the unexpected results with awk because you reference some variables using $. Example:
val = sprintf("%s", substr($2,1, index($2,"\<")-1));
printf "value in variable: %s\n", $val;
In your first line, you compute the value of val but in the second line, you use $val. The latter actually returns the value of the field with number val. So if val=2, then $val will return $2, i.e. the content of the second field.

Related

Show custom query data in Magento 2 admin grid

I have created a custom module which stores some data related to the product in a custom collection.
Now to show it as a report in the Magento 2 admin, I need to create a custom query to join it with the customer and product tables and do some aggregate functionality such as count grouped by the product.
Is there a way we can do that using custom SQL query and pass the whole result in the grid and it takes the relevant column names and shows it in the grid?
<?xml version="1.0"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="provider" xsi:type="string">bargain_offer_listing.bargain_offer_listing_data_source</item>
<item name="deps" xsi:type="string">bargain_offer_listing.bargain_offer_listing_data_source</item>
<item name="spinner" xsi:type="string">bargain_offer_listing_columns</item>
</item>
</argument>
<listingToolbar name="listing_top">
<bookmark name="bookmarks"/>
<columnsControls name="columns_controls"/>
<filterSearch name="fulltext"/>
<filters name="listing_filters"/>
<paging name="listing_paging"/>
</listingToolbar>
<dataSource name="bargain_offer_listing_data_source">
<argument name="dataProvider" xsi:type="configurableObject">
<argument name="class" xsi:type="string">MyModule\Bargain\Ui\DataProvider\OfferListingProvider
</argument>
<argument name="name" xsi:type="string">bargain_offer_listing_data_source</argument>
<argument name="primaryFieldName" xsi:type="string">entity_id</argument>
<argument name="requestFieldName" xsi:type="string">entity_id</argument>
<argument name="data" xsi:type="array">
<item name="update_url" xsi:type="url" path="mui/index/render"/>
<item name="storageConfig" xsi:type="array">
<item name="indexField" xsi:type="string">entity_id</item>
</item>
</argument>
</argument>
</dataSource>
<columns name="bargain_offer_listing_columns">
<column name="entity_id">
<settings>
<filter>textRange</filter>
<label translate="true">ID</label>
</settings>
</column>
<column name="product_sku">
<settings>
<filter>text</filter>
<label translate="true">Product Sku</label>
</settings>
</column>
<column name="product_name">
<settings>
<filter>text</filter>
<bodyTmpl>ui/grid/cells/text</bodyTmpl>
<label translate="true">Product Name</label>
</settings>
</column>
<column name="number_of_buyers">
<settings>
<filter>text</filter>
<label translate="true">No of buyers</label>
</settings>
</column>
<column name="times_bought">
<settings>
<filter>text</filter>
<label translate="true">Times Bought</label>
</settings>
</column>
</columns>
</listing>
This is my data provider class
use Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider;
class OfferListingProvider extends DataProvider
{
}
But I do not know how to utilize this. Any suggestions or guides is appreciated.

FastReport open source object data source

I try to use FastReport open source to build reports from data I'll provide to the report.
I've found what I want in the demos (https://github.com/FastReports/FastReport/tree/master/Demos/OpenSource/DataFromBusinessObject/DataFromBusinessObject)
In this demo, I see in the report file that a BusinessObjectDataSourceis used, which seems to be what I want to use.
However, I don't see a way to add this kind of source in the community designer. Do I need to add all of this manually ? Or is there a way to generate the needed markup ? I can't find the solution on their site.
I found a way by making the needed xml by hand like this:
<BusinessObjectDataSource Name="Invoices" ReferenceName="Invoices" Enabled="true">
<Column Name="Reference" DataType="System.String"/>
<Column Name="Date" DataType="System.String"/>
<Column Name="CompanyName" DataType="System.String"/>
<Column Name="InvoiceEmail" DataType="System.String"/>
<Column Name="VAT" DataType="System.String"/>
<Column Name="Street" DataType="System.String"/>
<Column Name="Number" DataType="System.String"/>
<Column Name="City" DataType="System.String"/>
<Column Name="ZipCode" DataType="System.String"/>
<Column Name="Country" DataType="System.String"/>
<Column Name="TotalPrice" DataType="System.Decimal"/>
<Column Name="VATValue" DataType="System.Decimal"/>
<Column Name="VATPercentage" DataType="System.Decimal"/>
<Column Name="VATComment" DataType="System.String"/>
</BusinessObjectDataSource>
The only drawback is that I need to update this if my object changes (but at least is is working !)
I found a way to generate an empty report with the fields generated from a business object.
You only have to create an empty report object, call "RegisterBusinessObject()" on its Dictionary property, and then save the report itself:
var report = new Report();
report.Dictionary.RegisterBusinessObject(
new List<Invoice>(), // a (empty) list of objects
"Invoices", // name of dataset
2, // depth of navigation into properties
true // enable data source
);
report.save(#"invoiceReport.frx");
You still need to update the report description if your object changes, but at least you don't have to code it by hand!

Liquibase generateChangelog creates wrong precision for Oracle

For some reason when I generate a change log with Liquibase it uses wrong precision. It generates a column with data type NUMBER(0,-127).
Does anybody know how to fix this?
<changeSet author="sfasdf (generated)" id="1357744702717-1">
<createTable schemaName="BLA" tableName="ADT_PAGE_ACCESS">
<column name="ID" type="NUMBER(0,-127)">
<constraints nullable="false" primaryKey="true" primaryKeyName="ADT_PAGE_ACCESS_PK" primaryKeyTablespace="ZON_IND1"/>
</column>
<column name="PAGE_ID" type="VARCHAR2(100 BYTE)">
<constraints nullable="false"/>
</column>
<column defaultValueComputed="sysdate" name="ACCESSED" type="DATE">
<constraints nullable="false"/>
</column>
<column name="CUSTOMER_ID" type="NUMBER(0,-127)"/>
<column name="USERID" type="VARCHAR2(25 BYTE)"/>
</createTable>
</changeSet>

LINQ TO SQL Mapping Error

Iam using LINQ To SQL with POCO's and XML mapping. I am getting the following error when I try to run the application: Cannot find type 'MyProject.DataTransfer.User' from mapping.
Below is the mapping:
<Table Name="Users" Member="User">
<Type Name= "MyProject.DataTrasnfer.User">
<Column Name="UserID" Member="UserID" DbType="Int NOT NULL IDENTITY" IsDbGenerated="true"
IsPrimaryKey="true"/>
<Column Name="UserName" Member="UserName" DbType="nvarchar(100) NOT NULL" />
<Column Name="Password" Member="Password" DbType="nvarchar(32)"/>
<Column Name="IsActive" Member="IsActive" DbType="bit NOT NULL"/>
<Column Name="InsertedBy" Member="InsertedBy" DbType="Int NOT NULL" />
<Column Name="InsertedDate" Member="InsertedDate" DbType="DateTime NOT NULL" />
<Column Name="UpdatedBy" Member="UpdatedBy" DbType="Int NOT NULL" />
<Column Name="UpdatedDate" Member="UpdatedDate" DbType="DateTime NOT NULL" />
<Column Name="Version" Member="Version" DbType="rowversion NOT NULL" IsDbGenerated="true"
IsVersion="true" AutoSync="Always"/>
</Type>
</Table>
But 'MyProject.DataTransfer.User' exists in the solution. What could be the possible reasons for this error?
Typo: MyProject.DataTrasnfer.User. You have transposed the s and the n.
I suppose that you have a class MyProject.DataTraSNfer.User in mapping and MyProject.DataTraNSfer.User in code. Misprint in post or in code?

LINQ to SQL: inner join with manual association on SQL 2000

I have two tables in a one to many relationship. (products and qty break pricing). At the database level I cannot create a relationship between the two tables. I brought those two tables into LINQ and created the association manually.
I need to do a big LINQ query and have the tables be joined. My problem is it's not using a join to get the data. LINQ is using 1 select on the main table, then 1 select for each row in that main table.
Dim db As New LSSStyleDataContext(connString)
Dim options As New DataLoadOptions()
options.LoadWith(Function(c As commerce_product) c.commerce_qty_breaks)
db.LoadOptions = options
Dim dbProducts = (From prods In db.commerce_products).ToList
Any thoughts on why this might be? Thanks!
Paul
EDIT: here are the two tables:
CREATE TABLE [dbo].[commerce_product](
[pf_id] [int] NOT NULL,
[name] [varchar](500) COLLATE SQL_Latin1_General_CP1_CI_AS
[description] [text] COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[restricted] [varchar](5) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
CONSTRAINT [PK_commerce_product_1] PRIMARY KEY NONCLUSTERED
(
[pf_id] ASC
) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
And the other table:
CREATE TABLE [dbo].[commerce_qty_break](
[pf_id] [int] NOT NULL,
[sku] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[qty] [int] NOT NULL,
[list_price] [int] NOT NULL,
[break_id] [int] NOT NULL,
CONSTRAINT [PK_commerce_qty_break] PRIMARY KEY CLUSTERED
(
[pf_id] ASC,
[qty] ASC,
[break_id] ASC
) ON [PRIMARY]
) ON [PRIMARY]
The DBML is straight forward with only the two tables. I created an association between the two tables, "commerce_product" being the parent and "commerce_qty_break" being the child joined by "PF_ID".
I can write something like this:
Dim dbproducts = From prods In db.commerce_products _
Join qtys In db.commerce_qty_breaks On prods.pf_id Equals qtys.pf_id _
Select prods
And i see that it joins on the table in the query, but as soon as i try and spin through the "qty_breaks" it starts executing selects to get that info.
I'm totally stumped.
Edit 2: Here is the DBML:
<?xml version="1.0" encoding="utf-8"?>
<Database Name="LSScommerceDB_DevB" Class="LSSStyleDataContext" xmlns="http://schemas.microsoft.com/linqtosql/dbml/2007">
<Connection Mode="AppSettings" ConnectionString="***" SettingsObjectName="HSLPriceUpdate.My.MySettings" SettingsPropertyName="LSScommerceDB_DevBConnectionString" Provider="System.Data.SqlClient" />
<Table Name="dbo.commerce_product" Member="commerce_products">
<Type Name="commerce_product">
<Column Name="pf_id" Type="System.Int32" DbType="Int NOT NULL" IsPrimaryKey="true" CanBeNull="false" />
<Column Name="name" Type="System.String" DbType="VarChar(500)" CanBeNull="true" />
<Column Name="description" Type="System.String" DbType="Text" CanBeNull="true" UpdateCheck="Never" />
<Column Name="list_price" Type="System.Int32" DbType="Int" CanBeNull="true" />
<Column Name="image_file" Type="System.String" DbType="VarChar(255)" CanBeNull="true" />
<Column Name="image_width" Type="System.Int32" DbType="Int" CanBeNull="true" />
<Column Name="image_height" Type="System.Int32" DbType="Int" CanBeNull="true" />
<Column Name="sale_price" Type="System.Int32" DbType="Int" CanBeNull="true" />
<Column Name="sale_start" Type="System.DateTime" DbType="DateTime" CanBeNull="true" />
<Column Name="sale_end" Type="System.DateTime" DbType="DateTime" CanBeNull="true" />
<Column Name="attr_label1" Type="System.String" DbType="VarChar(100)" CanBeNull="true" />
<Column Name="attr_label2" Type="System.String" DbType="VarChar(100)" CanBeNull="true" />
<Column Name="attr_label3" Type="System.String" DbType="VarChar(100)" CanBeNull="true" />
<Column Name="attr_label4" Type="System.String" DbType="VarChar(100)" CanBeNull="true" />
<Column Name="attr_label5" Type="System.String" DbType="VarChar(100)" CanBeNull="true" />
<Column Name="sku" Type="System.String" DbType="VarChar(100)" CanBeNull="true" />
<Column Name="UOM" Type="System.String" DbType="VarChar(50)" CanBeNull="true" />
<Column Name="Sell_Pack" Type="System.String" DbType="VarChar(50)" CanBeNull="true" />
<Column Name="mfg_model_number" Type="System.String" DbType="VarChar(50)" CanBeNull="true" />
<Column Name="mfg_id" Type="System.Int32" DbType="Int" CanBeNull="true" />
<Column Name="logo_file" Type="System.String" DbType="VarChar(255)" CanBeNull="true" />
<Column Name="drop_ship" Type="System.String" DbType="VarChar(50)" CanBeNull="true" />
<Column Name="lead_time" Type="System.Int32" DbType="Int" CanBeNull="true" />
<Column Name="hazard_flag" Type="System.String" DbType="VarChar(50)" CanBeNull="true" />
<Column Name="publish_date" Type="System.DateTime" DbType="DateTime" CanBeNull="true" />
<Column Name="restricted" Type="System.String" DbType="VarChar(5)" CanBeNull="true" />
<Association Name="commerce_product_commerce_qty_break" Member="commerce_qty_breaks" ThisKey="pf_id" OtherKey="pf_id" Type="commerce_qty_break" />
</Type>
</Table>
<Table Name="dbo.commerce_qty_break" Member="commerce_qty_breaks">
<Type Name="commerce_qty_break">
<Column Name="pf_id" Type="System.Int32" DbType="Int NOT NULL" IsPrimaryKey="true" CanBeNull="false" />
<Column Name="sku" Type="System.String" DbType="VarChar(100) NOT NULL" CanBeNull="false" />
<Column Name="qty" Type="System.Int32" DbType="Int NOT NULL" IsPrimaryKey="true" CanBeNull="false" />
<Column Name="list_price" Type="System.Int32" DbType="Int NOT NULL" CanBeNull="false" />
<Column Name="sale_price" Type="System.Int32" DbType="Int" CanBeNull="true" />
<Column Name="sale_start" Type="System.DateTime" DbType="DateTime NOT NULL" CanBeNull="false" />
<Column Name="sale_end" Type="System.DateTime" DbType="DateTime" CanBeNull="true" />
<Column Name="break_id" Type="System.Int32" DbType="Int NOT NULL" IsPrimaryKey="true" CanBeNull="false" />
<Association Name="commerce_product_commerce_qty_break" Member="commerce_product" ThisKey="pf_id" OtherKey="pf_id" Type="commerce_product" IsForeignKey="true" />
</Type>
</Table>
</Database>
EDIT 3: Apparently this is only an issue in SQL 2000. SQL 2008 works fine. I have other tables that do eager loading in SQL 2000 and i can't figure out what the difference is between these two tables.
I created a VB console app and created the schema as you have it here.
Also - the relationship is PK -> PK so does this mean it's supposed to be a one-to-one relationship?
I populated the tables with a row each (see below) and ran the code you've listed above. I ran SQL Profiler and it only queried once:
SELECT [t0].[pf_id], [t0].[name], [t0].[description], [t0].[restricted],
[t1].[pf_id] AS [pf_id2], [t1].[sku], [t1].[qty], [t1].[list_price],
[t1].[break_id], (
SELECT COUNT(*)
FROM [dbo].[commerce_qty_break] AS [t2]
WHERE [t2].[pf_id] = [t0].[pf_id]
) AS [value]
FROM [dbo].[commerce_product] AS [t0]
LEFT OUTER JOIN [dbo].[commerce_qty_break] AS [t1] ON [t1].[pf_id] = [t0].[pf_id]
ORDER BY [t0].[pf_id], [t1].[qty], [t1].[break_id]
I wanted to make sure that the Data Options was forcing a deep load, so I added some extra code - here's the full code I used (and only the single query as above was traced):
Dim options As New DataLoadOptions()
options.LoadWith(Function(c As commerce_product) c.commerce_qty_breaks)
db.LoadOptions = options
Dim dbProducts = (From prods In db.commerce_products).ToList
Dim dbProduct = dbProducts.First().commerce_qty_breaks
Dim x = dbProduct.First().list_price
Here's the test data:
INSERT INTO [Test].[dbo].[commerce_product] ([pf_id],[name],[description],[restricted]) VALUES (1,'Test','Test','Test')
GO
INSERT INTO [Test].[dbo].[commerce_qty_break] ([pf_id],[sku],[qty],[list_price],[break_id]) VALUES (1,'22',1,1,1)
GO
hey, not sure i completely understood your question, but here's some info,
By default LINQ to SQL adopts lazy binding, meaning it won't query the database until it needs to. That's why you're getting multiple queries.
There are few things you can do to avoid multiple hits on the DB:
You can turn off lazy binding globally in the LINQ to SQL designer. But then you'll always perform JOINS if your tables have any relationships.
You do the JOIN manually in the LINQ query. If you do this, you'll have to specify which "fields" you want to return in your LINQ query to get back the JOINED data. And if you do this, then you'll be returning an Anonymous type
NOTE: LINQ to SQL doesn't support LEFT JOINS. If you google LINQ to SQL Left Joins you'll see plenty of info on this particular subject
cheers, and good luck!
Go grab LINQPad. It's great for playing with stuff like this.
Did you try something like this?
Dim dbproducts = From prods In db.commerce_products _
Join qtys In db.commerce_qty_breaks On prods.pf_id Equals qtys.pf_id _
Select new {prods, qtys}
I ended up using the entity framework and all is well.

Resources