ColdFusion Function Error (cfc) - coldfusion-10

I am having a little problem with a cfc that is not supposed to return any thing. Its only function is to insert information into a couple database tables. I am getting a generic message stating "The value returned from the PutLocSalesRegisterInfo function is not of type boolean.". Is there anyone who have had a similar problem and fixed it somehow? Here is my function below.
<cffunction name="PutLocSalesRegisterInfo" access="public" output="false" returntype="boolean">
<cfargument name="OrgID" required="yes" type="any">
<cfargument name="LocID" required="yes" type="any">
<cfargument name="RegNum" required="yes" type="any">
<cfargument name="userID" required="yes" type="any">
<cfargument name="firstName" required="yes" type="any" default="">
<cfargument name="LastName" required="yes" type="any" default="">
<cfargument name="effectiveDate" required="yes" type="any" default="">
<cfargument name="VisaAmount" required="no" type="any" default="0.00">
<cfargument name="VisaCount" required="no" type="any" default="0">
<cfargument name="discoverCount" required="no" type="any" default="0">
<cfargument name="discoverAmount" required="no" type="any" default="0.00">
<cfargument name="MasterCardCount" required="no" type="any" default="0">
<cfargument name="MasterCardAmount" required="no" type="any" default="0.00">
<cfargument name="debitCount" required="no" type="any" default="0">
<cfargument name="debitAmount" required="no" type="any" default="0.00">
<cfargument name="AmericanExpressCount" required="no" type="any" default="0">
<cfargument name="AmericanExpressAmount" required="no" type="any" default="0.00">
<cfargument name="ccCountTotal" required="no" type="any" default="0">
<cfargument name="ccAmtTotal" required="no" type="any" default="0.00">
<cfargument name="CheckCount" required="no" type="any" default="0">
<cfargument name="CheckAmount" required="no" type="any" default="0.00">
<cfargument name="CreditIssuedCount" required="no" type="any" default="0">
<cfargument name="CreditIssuedAmount" required="no" type="any" default="0.00">
<cfargument name="eChecksCount" required="no" type="any" default="0">
<cfargument name="eChecksAmount" required="no" type="any" default="0.00">
<cfargument name="CreditRedeemedCount" required="no" type="any" default="0">
<cfargument name="CreditRedeemedAmount" required="no" type="any" default="0.00">
<cfargument name="GiftCertIssuedCount" required="no" type="any" default="0">
<cfargument name="GiftCertIssuedAmount" required="no" type="any" default="0.00">
<cfargument name="GiftCardIssuedCount" required="no" type="any" default="0">
<cfargument name="GiftCardIssuedAmount" required="no" type="any" default="0.00">
<cfargument name="GiftCertRedeemedCount" required="no" type="any" default="0">
<cfargument name="GiftCertRedeemedAmount" required="no" type="any" default="0.00">
<cfargument name="GiftCardRedeemedCount" required="no" type="any" default="0">
<cfargument name="GiftCardRedeemedAmount" required="no" type="any" default="0.00">
<cfargument name="VouchersCount" required="no" type="any" default="0">
<cfargument name="VouchersAmount" required="no" type="any" default="0.00">
<cfargument name="cashDonationsCount" required="no" type="any" default="0">
<cfargument name="cashDonationsAmount" required="no" type="any" default="0.00">
<cfargument name="ChangeRndUpCount" required="no" type="any" default="0">
<cfargument name="ChangeRndUpAmount" required="no" type="any" default="0.00">
<cfargument name="ExpectedCashfromRegister" required="no" type="any" default="0.00">
<cfargument name="ExpectedCashFromDrawer" required="no" type="any" default="0.00">
<cfargument name="CashTotal" required="no" type="any" default="0.00">
<cfargument name="CashTotalAmountEntered" required="no" type="any" default="0.00">
<cfargument name="Cashadjust" required="no" type="any" default="0.00">
<cfargument name="ActualCashMinusChangeStock" required="no" type="any" default="0.00">
<cfargument name="transactions" required="no" type="any" default="0">
<!--- <cfargument name="totalSalesandTax" required="no" type="any" default="0.00"/> --->
<cfargument name="salesTaxadjustment" required="no" type="any" default="0.00">
<cfargument name="salesTax" required="no" type="any" default="0.00">
<cfargument name="totalSales" required="no" type="any" default="0.00">
<cfargument name="taxExemptSales" required="no" type="any" default="0.00">
<!--- <cfargument name="commercialGoods" required="no" type="any" default="0.00"/> --->
<cfargument name="changeStock" required="no" type="any" default="0.00">
<cfargument name="overshort" required="no" type="any" default="0.00">
<!--- local empty variables --->
<cfset var PutRegSalesInfo ="">
<cfset var PutRegisterBalanceDetail ="">
<cfset var PutSalesCategories ="">
<cfset var PutCCDetail ="">
<!--- Strip commas and dollar signs from the argument --->
<cfset OverShort = ReplaceNoCase(ReplaceNoCase(Arguments.overshort,',','','ALL'),'$','','ALL')>
<cfset ActualCashMinusChangeStock = ReplaceNoCase(ReplaceNoCase(Arguments.ActualCashMinusChangeStock,',','','ALL'),'$','','ALL')>
<cfset cashTotal = ReplaceNoCase(ReplaceNoCase(Arguments.cashTotal,',','','ALL'),'$','','ALL')>
<cfset totalSales = ReplaceNoCase(ReplaceNoCase(Arguments.totalSales,',','','ALL'),'$','','ALL')>
<cfset ExpectedCashFromDrawer = ReplaceNoCase(ReplaceNoCase(Arguments.ExpectedCashFromDrawer,',','','ALL'),'$','','ALL')>
<cftry>
<cftransaction>
<cfquery name="PutRegSalesInfo" datasource="#application.dsn.name#">
INSERT INTO Data_Org_Location_Register_Totals
(
nOrganizationID
,nLocationID
,nRegisterNumber
,cCashierFirstName
,cCashierLastName
,dTotalActualCash
,dTotalActualCashLessChangeStock
,nCountCreditCardTransactions
,dTotalCreditCards
,nCountChecks
,dTotalChecks
,nCountEChecks
,dTotalEChecks
,nCountCreditIssued
,dTotalCreditIssued
,nCountCreditRedeemed
,dTotalCreditRedeemed
,nCountGiftCertIssued
,dTotalGiftCertIssued
,nCountGiftCertRedeemed
,dTotalGiftCertRedeemed
,nCountGiftCardIssued
,dTotalGiftCardIssued
,nCountGiftCardRedeemed
,dTotalGiftCardRedeemed
,nCountVouchers
,dTotalVouchers
,nCountCashDonations
,dTotalCashDonations
,dTotalTaxExemptSales
,nCountTransactions
,dTotalSales
,dSalesTax
,dSalesTaxAdjustment
,tEffectiveDate
,nAvailable
,tCreationDate
,nActive
,tLastUpdate
,cChangedBy
)
VALUES(
<cfqueryparam cfsqltype="cf_sql_integer" value="#Arguments.OrgID#"/>,
<cfqueryparam cfsqltype="cf_sql_integer" value="#Arguments.LocID#"/>,
<cfqueryparam cfsqltype="cf_sql_integer" value="#Arguments.RegNum#"/>,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#Arguments.firstName#"/>,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#Arguments.LastName#"/>,
<cfqueryparam cfsqltype="cf_sql_decimal" value="#DecimalFormat(cashTotal)#"/>,
<cfqueryparam cfsqltype="cf_sql_decimal" value="#DecimalFormat(ActualCashMinusChangeStock)#"/>,
<cfqueryparam cfsqltype="cf_sql_integer" value="#Arguments.ccCountTotal#"/>,
<cfqueryparam cfsqltype="cf_sql_decimal" value="#DecimalFormat(Arguments.ccAmtTotal)#"/>,
<cfqueryparam cfsqltype="cf_sql_integer" value="#Arguments.CheckCount#"/>,
<cfqueryparam cfsqltype="cf_sql_decimal" value="#DecimalFormat(Arguments.CheckAmount)#">,
<cfqueryparam cfsqltype="cf_sql_integer" value="#Arguments.eChecksCount#"/>,
<cfqueryparam cfsqltype="cf_sql_decimal" value="#DecimalFormat(Arguments.eChecksAmount)#"/>,
<cfqueryparam cfsqltype="cf_sql_integer" value="#Arguments.CreditIssuedCount#"/>,
<cfqueryparam cfsqltype="cf_sql_decimal" value="#DecimalFormat(Arguments.CreditIssuedAmount)#"/>,
<cfqueryparam cfsqltype="cf_sql_integer" value="#Arguments.CreditRedeemedCount#"/>,
<cfqueryparam cfsqltype="cf_sql_decimal" value="#DecimalFormat(Arguments.CreditRedeemedAmount)#"/>,
<cfqueryparam cfsqltype="cf_sql_integer" value="#Arguments.GiftCertIssuedCount#"/>,
<cfqueryparam cfsqltype="cf_sql_decimal" value="#DecimalFormat(Arguments.GiftCertIssuedAmount)#"/>,
<cfqueryparam cfsqltype="cf_sql_integer" value="#Arguments.GiftCertRedeemedCount#"/>,
<cfqueryparam cfsqltype="cf_sql_decimal" value="#DecimalFormat(Arguments.GiftCertRedeemedAmount)#"/>,
<cfqueryparam cfsqltype="cf_sql_integer" value="#Arguments.GiftCardIssuedCount#"/>,
<cfqueryparam cfsqltype="cf_sql_decimal" value="#DecimalFormat(Arguments.GiftCardIssuedAmount)#"/>,
<cfqueryparam cfsqltype="cf_sql_integer" value="#Arguments.GiftCardRedeemedCount#"/>,
<cfqueryparam cfsqltype="cf_sql_decimal" value="#DecimalFormat(Arguments.GiftCardRedeemedAmount)#"/>,
<cfqueryparam cfsqltype="cf_sql_integer" value="#Arguments.VouchersCount#"/>,
<cfqueryparam cfsqltype="cf_sql_decimal" value="#DecimalFormat(Arguments.VouchersAmount)#"/>,
<cfqueryparam cfsqltype="cf_sql_integer" value="#Arguments.CashDonationsCount#"/>,
<cfqueryparam cfsqltype="cf_sql_decimal" value="#DecimalFormat(Arguments.CashDonationsAmount)#"/>,
<cfqueryparam cfsqltype="cf_sql_decimal" value="#DecimalFormat(Arguments.taxExemptSales)#"/>,
<cfqueryparam cfsqltype="cf_sql_integer" value="#Arguments.Transactions#"/>,
<cfqueryparam cfsqltype="cf_sql_decimal" value="#DecimalFormat(totalSales)#"/>,
<cfqueryparam cfsqltype="cf_sql_decimal" value="#DecimalFormat(Arguments.salesTax)#"/>,
<cfqueryparam cfsqltype="cf_sql_decimal" value="#DecimalFormat(Arguments.salesTaxadjustment)#"/>,
<cfqueryparam cfsqltype="cf_sql_date" value="#DateFormat(CreateODBCDateTime(Arguments.effectiveDate), 'dd/mm/yyyy')#"/>,
<cfqueryparam cfsqltype="cf_sql_integer" value="#val(1)#"/>,
GetDate(),
<cfqueryparam cfsqltype="cf_sql_integer" value="#val(1)#"/>,
GetDate(),
<cfqueryparam cfsqltype="cf_sql_integer" value="#Arguments.userID#"/>
)
SELECT SCOPE_IDENTITY() AS New_PutRegSalesInfo_ID
</cfquery>
<!--- Create random unique Ref number (dont know why this is needed if there is a PK)--->
<cfset local.random_part = Randomize(PutRegSalesInfo.New_PutRegSalesInfo_ID, "SHA1PRNG")>
<cfset local.UserRefToHash = Now() & "ref" & PutRegSalesInfo.New_PutRegSalesInfo_ID & ":" & local.random_part>
<cfset local.NewSalesInfoRefID = Hash(local.UserRefToHash, 'sha-256', 'iso-8859-1')>
<cfquery datasource="#application.dsn.name#" name="UpdateRegisterTotalsRef">
update Data_Org_Location_Register_Totals
set cRegisterTotalsRefID = <cfqueryparam cfsqltype="cf_sql_varchar" value="#local.NewSalesInfoRefID#"/>
where nID = <cfqueryparam cfsqltype="cf_sql_integer" value="#PutRegSalesInfo.New_PutRegSalesInfo_ID#"/>
</cfquery>
<cfquery datasource="#application.dsn.name#" name="PutRegisterBalanceDetail">
Insert into Data_Org_Location_Register_BalanceDetail (
nRegisterTotalsID,
nOrganizationID,
nLocationID,
dExpectedCashFromRegister,
dCashAdjustments,
dAdjustedExpectedCashFromRegister,
dChangeStock,
dOverShort,
tCreationDate,
nActive,
tLastUpdate,
cChangedBy
)
values (
<cfqueryparam cfsqltype="cf_sql_integer" value="#PutRegSalesInfo.New_PutRegSalesInfo_ID#"/>,
<cfqueryparam cfsqltype="cf_sql_integer" value="#Arguments.OrgID#"/>,
<cfqueryparam cfsqltype="cf_sql_integer" value="#Arguments.LocID#"/>,
<cfqueryparam cfsqltype="cf_sql_decimal" value="#DecimalFormat(Arguments.ExpectedCashFromRegister)#"/>,
<cfqueryparam cfsqltype="cf_sql_decimal" value="#Arguments.CashAdjust#"/>,
<cfqueryparam cfsqltype="cf_sql_decimal" value="#DecimalFormat(ExpectedCashFromDrawer)#"/>,
<cfqueryparam cfsqltype="cf_sql_decimal" value="#DecimalFormat(Arguments.ChangeStock)#"/>,
<cfqueryparam cfsqltype="cf_sql_decimal" value="#DecimalFormat(OverShort)#"/>,
GetDate(),
<cfqueryparam cfsqltype="cf_sql_integer" value="#val(1)#"/>,
GetDate(),
<cfqueryparam cfsqltype="cf_sql_integer" value="#Arguments.UserID#"/>
)
</cfquery>
<!--- Get the number of CategoryIDs from the list then loop that many times--->
<cfloop index="i" from="1" to="#ListLen(Arguments.CategoryList)#"><!--- loop through the category form fields --->
<cfquery name="PutSalesCategories" datasource="#application.dsn.name#">
INSERT INTO Data_Org_Location_Register_CategorySales
(nOrganizationID
,nLocationID
,nRegisterTotalsID
,nOrgCategoryID
,nCount
,dAmount
,dAdjustment
,dTotal
,nAvailable
,tCreationDate
,nActive
,tLastUpdate
,cChangedBy
)
VALUES(
<cfqueryparam cfsqltype="cf_sql_integer" value="#Arguments.OrgID#"/>,
<cfqueryparam cfsqltype="cf_sql_integer" value="#Arguments.LocID#"/>,
<cfqueryparam cfsqltype="cf_sql_integer" value="#PutRegSalesInfo.New_PutRegSalesInfo_ID#"/>,
<cfqueryparam cfsqltype="cf_sql_integer" value="#Arguments.categoryID[i]#"/>,
<cfqueryparam cfsqltype="cf_sql_integer" value="#Arguments.categoryCount[i]#"/>,
<cfqueryparam cfsqltype="cf_sql_decimal" value="#DecimalFormat(Arguments.Amount[i])#"/>,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#Arguments.Adjustment[i]#"/>,
<cfqueryparam cfsqltype="cf_sql_decimal" value="#DecimalFormat(Arguments.total[i])#"/>,
<cfqueryparam cfsqltype="cf_sql_integer" value="#val(1)#"/>,
GetDate(),
<cfqueryparam cfsqltype="cf_sql_integer" value="#val(1)#"/>,
GetDate(),
<cfqueryparam cfsqltype="cf_sql_interger" value="#Arguments.UserID#"/>
)
</cfquery>
<cfset i = i + 1>
</cfloop>
<cfquery datasource="#application.dsn.name#" name="PutCCDetail">
INSERT INTO Data_Org_Location_Register_CreditCardDetail
(
nRegisterTotalsID
,nOrganizationID
,nLocationID
,nCountVisa
,dTotalVisa
,nCountMasterCard
,dTotalMasterCard
,nCountAmericanExpress
,dTotalAmericanExpress
,nCountDiscover
,dTotalDiscover
,nCountDebit
,dTotalDebit
,nAvailable
,tCreationDate
,nActive
,tLastUpdate
,cChangedBy
)
VALUES(
<cfqueryparam cfsqltype="cf_sql_integer" value="#PutRegSalesInfo.New_PutRegSalesInfo_ID#"/>,
<cfqueryparam cfsqltype="cf_sql_integer" value="#Arguments.OrgID#"/>,
<cfqueryparam cfsqltype="cf_sql_integer" value="#Arguments.LocID#"/>,
<cfqueryparam cfsqltype="cf_sql_integer" value="#Arguments.VisaCount#"/>,
<cfqueryparam cfsqltype="cf_sql_decimal" value="#DecimalFormat(Arguments.VisaAmount)#"/>,
<cfqueryparam cfsqltype="cf_sql_integer" value="#Arguments.MasterCardCount#"/>,
<cfqueryparam cfsqltype="cf_sql_decimal" value="#DecimalFormat(Arguments.MasterCardAmount)#"/>,
<cfqueryparam cfsqltype="cf_sql_integer" value="#Arguments.AmericanExpressCount#"/>,
<cfqueryparam cfsqltype="cf_sql_decimal" value="#DecimalFormat(Arguments.AmericanExpressAmount)#"/>,
<cfqueryparam cfsqltype="cf_sql_integer" value="#Arguments.DiscoverCount#"/>,
<cfqueryparam cfsqltype="cf_sql_decimal" value="#DecimalFormat(Arguments.DiscoverAmount)#"/>,
<cfqueryparam cfsqltype="cf_sql_integer" value="#Arguments.DebitCount#"/>,
<cfqueryparam cfsqltype="cf_sql_decimal" value="#DecimalFormat(Arguments.DebitAmount)#"/>,
<cfqueryparam cfsqltype="cf_sql_integer" value="#val(1)#"/>,
GetDate(),
<cfqueryparam cfsqltype="cf_sql_integer" value="#val(1)#"/>,
GetDate(),
<cfqueryparam cfsqltype="cf_sql_interger" value="#Arguments.UserID#"/>
)
</cfquery>
</cftransaction>
<cfreturn true>
<cfcatch>
<cfinvoke method="errorHandler" argumentcollection="#ARGUMENTS#" />
</cfcatch>
</cftry>
</cffunction>

If your catch block is executed, there would be no return.
Maybe you want to return false as the last line of your cfcatch.
Otherwise put the cfreturn true as the last line of the function.
Can you verify that catch block is not being executed?

Related

How to create a ColdFusion REST end-point which accepts query parameters

Here is the code snippet I have tried to create a REST end point with query parameters,
<cfcomponent rest="true" restpath="api">
<cffunction name="getUsersQuery" restpath="Users?filter={query}" access="remote" returntype="struct" httpmethod="GET" produces="application/json">
<cfargument name="query" type="any" required="yes" restargsource="query" />
<cfset var response = {} />
<cfset response["message"] = "Test" />
<cfreturn response>
</cffunction>
</cfcomponent>
But when I tried to call the end point like below it gives "Method Not Allowed"
http://localhost:8010/rest/v1/api/Users?filter=userName eq "test"
Any help would be greatly appreciated.
You don't need to provide ?filter={query} in the rest path since you have mentioned restargsource="query" in the argument. Also the argument name should be the URL key value.
<cffunction name="getUsersQuery" restpath="Users" access="remote" returntype="struct" httpmethod="GET" produces="application/json">
<cfargument name="filter" type="any" required="yes" restargsource="query" />
<cfset var response = {} />
<cfset response["message"] = "Test" />
<cfreturn response>
</cffunction>

CFQL Search method using an OR expression among multiple properties

I'm trying to ellaborate a SEARCH CFQL method.
I have either a property TownId set or a property TownLabel in the entity Address:
TownId is set if the address got affected a Town from a referential (Towns are stored in another DB and are referenced only by ID).
TownLabel is set if none of the known Towns was found. (e.g. Name of a town abroad)
In my SEARCH method I want to look for users having as a town, either the townLabel OR possible towns from the referential whoes name contains the value townLabel.
Long story short, my CFQL methods is as follow
SEARCH(string[] townIds, string townLabel) WHERE Adresses.TownId IN (#townIds) OR Adresses.TownLabel LIKE '%'+#townLabel+'%'
Despite the OR operator, the generated SQL appears with the AND operator as below.
My question: is it normal ?
CREATE PROCEDURE [dbo].[User_AdvancedSearch]
(
#townIds [nvarchar] (max) = NULL,
#townLabel [nvarchar] (256) = NULL,
#_orderBy0 [nvarchar] (64) = NULL,
#_orderByDirection0 [bit] = 0
)
AS
SET NOCOUNT ON
DECLARE #sql nvarchar(max), #paramlist nvarchar(max)
SELECT #sql=
'SELECT DISTINCT [User].[User_UserId], [User].[User_Name], [User].[User_Association_AssociationId], [User].[_trackLastWriteTime], [User].[_trackCreationTime], [User].[_trackLastWriteUser], [User].[_trackCreationUser], [User].[_rowVersion]
FROM [User]
LEFT OUTER JOIN [Address] ON ([User].[User_UserId] = [Address].[Address_User_UserId])
WHERE ((1 = 1) AND (1 = 1))'
SELECT #paramlist = '#townIds nvarchar (max),
#townLabel nvarchar (256),
#_orderBy0 nvarchar (64),
#_orderByDirection0 bit'
IF #townIds IS NOT NULL
SELECT #sql = #sql + ' AND ([Address].[Address_TownId] IN ((SELECT [Item] FROM [dbo].cf_SplitString(#townIds, nchar(1)))))'
IF #townLabel IS NOT NULL
SELECT #sql = #sql + ' AND (([Address].[Address_TownLabel] LIKE ((''%'' + #townLabel) + ''%'')))'
EXEC sp_executesql #sql, #paramlist,
#townIds,
#townLabel,
#_orderBy0,
#_orderByDirection0
RETURN
GO
The schema is given below
<cf:project defaultNamespace="WcfServices.Model" xmlns:cf="http://www.softfluent.com/codefluent/2005/1" xmlns:cfx="http://www.softfluent.com/codefluent/modeler/2008/1" xmlns:cfps="http://www.softfluent.com/codefluent/producers.sqlserver/2005/1" xmlns:cfom="http://www.softfluent.com/codefluent/producers.model/2005/1" xmlns:cfsps="http://www.softfluent.com/codefluent/producers.sqlpivotscript/2013/1" createDefaultMethodForms="true" createDefaultApplication="false" createDefaultHints="false">
<cf:import path="Default.Surface.cfp" />
<cf:entity name="Association" namespace="Example.Model.Association" categoryPath="/WcfServices.Model">
<cf:property name="AssociationId" key="true" persistenceEnforce="true" />
<cf:property name="Label" persistenceEnforce="true" />
<cf:property name="Users" typeName="Example.Model.Association.UserCollection" relationPropertyName="Association" />
</cf:entity>
<cf:producer name="SQL Server" typeName="CodeFluent.Producers.SqlServer.SqlServerProducer, CodeFluent.Producers.SqlServer">
<cf:configuration produceViews="true" targetDirectory="..\WcfServices.persistence" cfx:targetProject="..\WcfServices.persistence\WcfServices.persistence.sqlproj" cfx:targetProjectLayout="Update, DontRemove" />
</cf:producer>
<cf:producer name="Business Object Model (BOM)" typeName="CodeFluent.Producers.CodeDom.CodeDomProducer, CodeFluent.Producers.CodeDom">
<cf:configuration compileWithVisualStudio="true" compile="false" codeDomProviderTypeName="CSharp" targetDirectory="..\WcfServices.model" cfx:targetProject="..\WcfServices.model\WcfServices.model.csproj" cfx:targetProjectLayout="Update">
</cf:configuration>
</cf:producer>
<cf:entity name="User" namespace="Example.Model.Association" categoryPath="/WcfServices.Model">
<cf:property name="UserId" key="true" persistenceEnforce="true" />
<cf:property name="Name" persistenceEnforce="true" />
<cf:property name="Association" typeName="Example.Model.Association.Association" relationPropertyName="Users" />
<cf:property name="Adresses" typeName="Example.Model.Association.AddressCollection" relationPropertyName="User" persistenceEnforce="true" />
<cf:method name="AdvancedSearch" body="SEARCH(string[] townIds, string townLabel) WHERE Adresses.TownId IN (#townIds) OR Adresses.TownLabel LIKE '%%'+#townLabel+'%%'" />
</cf:entity>
<cf:producer name="SQL Server Pivot Script" typeName="CodeFluent.Producers.SqlServer.SqlPivotScriptProducer, CodeFluent.Producers.SqlServer">
<cf:configuration targetDirectory="..\WcfServices.web" cfx:targetProject="..\WcfServices.web\WcfServices.web.csproj" cfx:targetProjectLayout="Update" />
</cf:producer>
<cf:entity name="Address" namespace="Example.Model.Association" categoryPath="/WcfServices.Model">
<cf:property name="AddressId" key="true" persistenceEnforce="true" />
<cf:property name="Line" persistenceEnforce="true" />
<cf:property name="User" typeName="Example.Model.Association.User" relationPropertyName="Adresses" persistenceEnforce="true" />
<cf:property name="TownLabel" />
<cf:property name="TownId" typeName="guid" />
</cf:entity>
</cf:project>
EDIT 15/09/2016 - adding original CFQL + schema.
Original CFQL method:
SEARCH (string firstname, string name, int[] groups, string postalCode, string townLabel, string mail, string[] townId, guid structureId, guid countryId) WHERE Firstname LIKE '%'+#firstname+'%' AND Name LIKE '%'+#name+'%' AND (Address.PostalCode LIKE '%'+#postalCode+'%' OR StructureContacts.Address.PostalCode LIKE '%'+#postalCode+'%') AND ( Address.TownLabel LIKE '%'+#townLabel+'%' OR StructureContacts.Address.TownLabel LIKE '%'+#townLabel+'%' OR Address.TownId IN (#townId) OR StructureContacts.Address.TownId IN(#townId)) AND (StructureContacts.Groups.Value IN (#groups) OR Groups.Value IN (#groups)) AND StructureContacts.Structure.StructureId = #structureId and (Address.Email LIKE '%'+#mail+'%' OR StructureContacts.Address.Email LIKE '%'+#mail+'%') AND (Address.CountryId = #countryId OR StructureContacts.Address.CountryId = #countryId) order by Name, Firstname
Schema:
<cf:project defaultNamespace="Example.Models" xmlns:cf="http://www.softfluent.com/codefluent/2005/1">
<cf:enumeration name="enumStructureType" namespace="Example.Models.Contact.Structure" categoryPath="/RH">
<cf:enumerationValue name="ENTERPRISE" />
<cf:enumerationValue name="ASSOCIATION" />
<cf:enumerationValue name="OTHER_ASSOCIATION" />
<cf:enumerationValue name="SUPPLIER" />
<cf:enumerationValue name="PUBLIC_ORGANIZATION" />
</cf:enumeration>
<cf:entity name="Structure" defaultUsePersistenceDefaultValue="false" defaultPersistenceEnforce="false" namespace="Example.Models.Contact.Structure" categoryPath="/RH" storeName="ExampleStoreName">
<cf:property name="StructureId" key="true" />
<cf:property name="Sigle" />
<cf:property name="CorporateName" />
<cf:property name="Code" />
<cf:property name="Comment">
<cf:rule typeName="StringValidate" maxLength="2000" />
</cf:property>
<cf:property name="Siret" xmlns:cf="http://www.softfluent.com/codefluent/2005/1" collectionKey="false">
<cf:rule typeName="RegularExpressionValidate" expression="[\d]{14,14}" />
</cf:property>
<cf:property name="Type" xmlns:cf="http://www.softfluent.com/codefluent/2005/1" defaultValue="EstablishmentType.PRINCIPAL" typeName="{0}.Contact.Structure.enumStructureType" collectionKey="false" />
<cf:property name="Groups" set="true" cascadeSave="After" cascadeDelete="Before" typeName="{0}.Contact.Contact.GroupCollection" />
<cf:property name="ApeId" typeName="guid" />
<cf:property name="Address" cascadeSave="After" cascadeDelete="Before" typeName="{0}.Contact.Contact.Address" relationSchema="Contact" />
<cf:property name="EstablishmentType" typeName="{0}.Contact.Structure.enumEstablishmentType" />
<cf:property name="ParentStructure" readOnSave="true" typeName="{0}.Contact.Structure.Structure" relationPropertyName="ChildrenStructures" />
<cf:property name="ChildrenStructures" set="true" cascadeSave="After" cascadeDelete="Before" typeName="{0}.Contact.Structure.StructureCollection" relationPropertyName="ParentStructure" />
<cf:property name="OpeningHours" maxLength="2000" />
<cf:method name="SimpleSearchStructures" body="SEARCH (string keyword) WHERE CorporateName LIKE '%%'+#keyword+'%%' OR Code LIKE '%%'+#keyword+'%%' OR Comment LIKE '%%'+#keyword+'%%' OR Sigle LIKE '%%'+#keyword+'%%' OR Siret LIKE '%%'+#keyword+'%%' OR Address.Email LIKE '%%'+#keyword+'%%' ORDER BY CorporateName" />
<cf:method name="AdvancedSearchStructures" body="SEARCH (string corporateName, string email, string postalCode, string townLabel, string[] townIds, int[] groups, guid countryId, int[] types) WHERE CorporateName LIKE '%%'+#corporateName+'%%' AND Address.Email LIKE '%%'+#email+'%%' AND (Address.TownLabel LIKE '%%'+#townLabel+'%%' OR Address.TownId IN (#townIds)) AND Address.PostalCode LIKE '%%'+#postalCode+'%%' AND Address.CountryId = #countryId AND Groups.Value IN (#groups) AND Type IN (#types) ORDER BY CorporateName" />
<cf:rule typeName="OnBeforeSave" methodName="BeforeSave" />
<cf:method name="DeleteById" body="DELETE(guid id) WHERE StructureId = #id" />
</cf:entity>
<cf:entity name="StructureAssociation" baseTypeName="Example.Models.Contact.Structure.Structure" namespace="Example.Models.Contact.Structure" categoryPath="/Example.Models" storeName="ExampleStoreName">
<cf:property name="ParutionDateOJ" xmlns:cf="http://www.softfluent.com/codefluent/2005/1" typeName="date" persistenceEnforce="true" collectionKey="false" />
<cf:property name="BasinId" xmlns:cf="http://www.softfluent.com/codefluent/2005/1" typeName="guid" relationSchema="Contact" persistenceEnforce="true" collectionKey="false" />
<cf:property name="ReceiptNum" xmlns:cf="http://www.softfluent.com/codefluent/2005/1" persistenceEnforce="true" collectionKey="false" />
<cf:property name="PrefectureId" typeName="guid" persistenceEnforce="true" />
<cf:property name="CreationDate" typeName="date" persistenceEnforce="true" />
<cf:property name="CartePecheAappmaId" persistenceEnforce="true" />
<cf:method name="LoadAssociationStructure" body="LOADONE WHERE EstablishmentType = 3" />
</cf:entity>
<cf:entity name="StructureContact" defaultUsePersistenceDefaultValue="false" setType="List" namespace="Example.Models.Contact.Structure" categoryPath="/RH" storeName="ExampleStoreName">
<cf:property name="Function" defaultValue="enumFunctionType.PRESIDENT" typeName="{0}.Contact.Structure.enumFunctionType" persistenceEnforce="true" collectionKey="false" />
<cf:property name="StartDateFunction" usePersistenceDefaultValue="true" typeName="date" persistenceEnforce="true" collectionKey="false" />
<cf:property name="EndDateFunction" usePersistenceDefaultValue="true" typeName="date" persistenceEnforce="true" collectionKey="false" />
<cf:property name="Contact" typeName="{0}.Contact.Contact.Contact" relationPropertyName="StructureContacts" relationSchema="Contact" persistenceEnforce="true" />
<cf:property name="Address" cascadeSave="After" cascadeDelete="Before" typeName="{0}.Contact.Contact.Address" relationSchema="Contact" persistenceEnforce="true" />
<cf:property name="Groups" set="true" cascadeSave="After" cascadeDelete="Before" typeName="{0}.Contact.Contact.GroupCollection" persistenceEnforce="true" />
<cf:property name="DocumentUrl" typeName="guid" persistenceEnforce="true" />
<cf:property name="Structure" typeName="{0}.Contact.Structure.Structure" persistenceEnforce="true">
<cf:attribute name="Newtonsoft.Json.JsonIgnore" class="" />
</cf:property>
<cf:property name="StructureContactId" key="true" persistenceEnforce="true" />
<cf:property name="AdditionalDate" usePersistenceDefaultValue="true" typeName="date" persistenceEnforce="true" />
<cf:property name="DocumentName" persistenceEnforce="true" />
<cf:method name="LoadBoardMembers" body="LOAD (int[] functions) WHERE Function IN (#functions)" />
</cf:entity>
<cf:entity name="StructureEnterprise" baseTypeName="Example.Models.Contact.Structure.Structure" namespace="Example.Models.Contact.Structure" categoryPath="/Example.Models" storeName="ExampleStoreName">
<cf:property name="VATNum" xmlns:cf="http://www.softfluent.com/codefluent/2005/1" persistenceEnforce="true" collectionKey="false" />
</cf:entity>
<cf:entity name="StructureOtherAssociation" baseTypeName="Example.Models.Contact.Structure.Structure" namespace="Example.Models.Contact.Structure" categoryPath="/Example.Models" storeName="ExampleStoreName">
<cf:property name="ReceiptNum" xmlns:cf="http://www.softfluent.com/codefluent/2005/1" persistenceEnforce="true" collectionKey="false" />
<cf:property name="SkillTerritoryType" typeName="{0}.Contact.Structure.enumStructureSkillTerritoryType" persistenceEnforce="true" />
</cf:entity>
<cf:entity name="Address" defaultUsePersistenceDefaultValue="false" namespace="Example.Models.Contact.Contact" categoryPath="/RH" persistenceName="Address" storeName="ExampleStoreName">
<cf:property name="AddressId" key="true" persistenceEnforce="true" />
<cf:property name="Line1" persistenceEnforce="true" />
<cf:property name="Line2" persistenceEnforce="true" />
<cf:property name="IsActive" typeName="bool" persistenceEnforce="true" />
<cf:property name="Landline" persistenceEnforce="true" />
<cf:property name="Email" persistenceEnforce="true">
<cf:rule typeName="EmailValidate" />
</cf:property>
<cf:property name="Fax" persistenceEnforce="true" />
<cf:property name="Website" persistenceEnforce="true" />
<cf:property name="Mobile" persistenceEnforce="true" />
<cf:property name="DirectLine" persistenceEnforce="true" />
<cf:property name="ProfessionalLine" persistenceEnforce="true" />
<cf:property name="TownId" typeName="guid" persistenceEnforce="true" />
<cf:property name="TownLabel" persistenceEnforce="true" />
<cf:property name="CountryId" typeName="guid" persistenceEnforce="true" />
<cf:property name="PostalCode" persistenceEnforce="true" />
<cf:rule typeName="OnBeforeSave" methodName="BeforeSave" />
</cf:entity>
<cf:entity name="Contact" defaultUsePersistenceDefaultValue="false" namespace="Example.Models.Contact.Contact" categoryPath="/RH" persistenceName="Contact" storeName="ExampleStoreName">
<cf:property name="Name" persistenceEnforce="true" />
<cf:property name="Firstname" persistenceEnforce="true" />
<cf:property name="Civility" defaultValue="CivilityContact.Mr" typeName="{0}.Global.Civility" persistenceEnforce="true" />
<cf:property name="DateOfBirth" serializationNullable="true" modelNullable="true" typeName="date" persistenceEnforce="true" />
<cf:property name="Comment" persistenceEnforce="true">
<cf:rule typeName="StringValidate" maxLength="2000" />
</cf:property>
<cf:property name="ContactId" key="true" persistenceEnforce="true" />
<cf:property name="StructureContacts" set="true" cascadeSave="After" cascadeDelete="Before" typeName="{0}.Contact.Structure.StructureContactCollection" relationPropertyName="Contact" relationSchema="Contact" persistenceEnforce="true" />
<cf:property name="Address" cascadeSave="After" cascadeDelete="Before" typeName="{0}.Contact.Contact.Address" relationSchema="Contact" persistenceEnforce="true" />
<cf:property name="TownOfBirthLabel" persistenceEnforce="true" />
<cf:property name="TownIdOfBirth" typeName="guid" persistenceEnforce="true" />
<cf:property name="CountryIdOfBirth" typeName="guid" persistenceEnforce="true" />
<cf:property name="DepartmentIdOfBirth" typeName="guid" persistenceEnforce="true" />
<cf:property name="PostalCode" persistenceEnforce="true" />
<cf:property name="Groups" set="true" cascadeSave="After" cascadeDelete="Before" typeName="{0}.Contact.Contact.GroupCollection" persistenceEnforce="true" />
<cf:property name="CartePecheMemberId" persistenceEnforce="true" />
<cf:method name="AdvancedSearchContactsTownLabel" body="SEARCH (string firstname, string name, int[] groups, string postalCode, string townLabel, string mail, string[] townId, guid structureId, guid countryId) WHERE Firstname LIKE '%%'+#firstname+'%%' AND Name LIKE '%%'+#name+'%%' AND (Address.PostalCode LIKE '%%'+#postalCode+'%%' OR StructureContacts.Address.PostalCode LIKE '%%'+#postalCode+'%%') AND ( Address.TownLabel LIKE '%%'+#townLabel+'%%' OR StructureContacts.Address.TownLabel LIKE '%%'+#townLabel+'%%' OR Address.TownId IN (#townId) OR StructureContacts.Address.TownId IN(#townId)) AND (StructureContacts.Groups.Value IN (#groups) OR Groups.Value IN (#groups)) AND StructureContacts.Structure.StructureId = #structureId and (Address.Email LIKE '%%'+#mail+'%%' OR StructureContacts.Address.Email LIKE '%%'+#mail+'%%') AND (Address.CountryId = #countryId OR StructureContacts.Address.CountryId = #countryId) order by Name, Firstname" />
<cf:method name="SimpleSearchContacts" body="SEARCH(string keywords) WHERE Firstname LIKE '%%'+#keywords+'%%' OR Name LIKE '%%'+#keywords+'%%' OR Address.Email LIKE '%%'+#keywords+'%%' OR StructureContacts.Address.Email LIKE '%%'+#keywords+'%%' order by Name, Firstname" />
<cf:rule typeName="OnBeforeSave" methodName="BeforeSave" />
<cf:method name="SearchContactByName" body="SEARCH(string nameOrFirstName, int[] functions) WHERE (Name LIKE '%%'+#nameOrFirstName+'%%' OR Firstname LIKE '%%'+#nameOrFirstName+'%%') AND StructureContacts.Function IN (#functions)" />
<cf:method name="LoadContactsByDateFunction" body="LOAD (date currentDate, int[] functions) WHERE StructureContacts.Function IN (#functions) AND ( StructureContacts.StartDateFunction <= #currentDate OR NOT StructureContacts.StartDateFunction EXISTS )
AND ( StructureContacts.EndDateFunction > #currentDate OR NOT StructureContacts.EndDateFunction EXISTS )" />
<cf:method name="DeleteById" body="DELETE(guid id) WHERE ContactId = #id" />
<cf:method name="AdvancedSearchContactTownId" body="SEARCH (string firstname, string name, int[] groups, string postalCode, string townLabel, string mail, string[] townId, guid structureId, guid countryId) WHERE Firstname LIKE '%%'+#firstname+'%%' AND Name LIKE '%%'+#name+'%%' AND (Address.PostalCode LIKE '%%'+#postalCode+'%%' OR StructureContacts.Address.PostalCode LIKE '%%'+#postalCode+'%%') AND (Address.TownId IN (#townId) OR StructureContacts.Address.TownId IN(#townId) ) AND (StructureContacts.Groups.Value IN (#groups) OR Groups.Value IN (#groups)) AND StructureContacts.Structure.StructureId = #structureId and (Address.Email LIKE '%%'+#mail+'%%' OR StructureContacts.Address.Email LIKE '%%'+#mail+'%%') AND (Address.CountryId = #countryId OR StructureContacts.Address.CountryId = #countryId) order by Name, Firstname" />
</cf:entity>
<cf:entity name="Group" defaultUsePersistenceDefaultValue="false" namespace="Example.Models.Contact.Contact" categoryPath="/RH" storeName="ExampleStoreName">
<cf:property name="GroupId" key="true" persistenceEnforce="true" />
<cf:property name="Value" defaultValue="enumGroupType.DGS" typeName="int" persistenceEnforce="true" />
</cf:entity>
<cf:entity name="StructureSupplier" baseTypeName="Example.Models.Contact.Structure.Structure" namespace="Example.Models.Contact.Structure" categoryPath="/Example.Models" storeName="ExampleStoreName">
<cf:property name="CartePecheDepositaireId" persistenceEnforce="true" />
<cf:property name="NumberExt" persistenceEnforce="true" />
<cf:property name="DocumentUrl" persistenceEnforce="true" />
<cf:property name="DocumentName" persistenceEnforce="true" />
<cf:property name="IsKeyAccount" typeName="bool" persistenceEnforce="true" />
<cf:property name="ConventionDate" typeName="date" persistenceEnforce="true" />
</cf:entity>
<cf:enumeration name="enumEstablishmentType" namespace="Example.Models.Contact.Structure" categoryPath="/Example.Models">
<cf:enumerationValue name="HEAD_OFFICE" />
<cf:enumerationValue name="SECONDARY" />
<cf:enumerationValue name="DELEGATION" />
<cf:enumerationValue name="ASSOCIATION" />
</cf:enumeration>
<cf:enumeration name="enumFunctionType" namespace="Example.Models.Contact.Structure" categoryPath="/Example.Models">
<cf:enumerationValue name="DIRECTOR" />
<cf:enumerationValue name="EMPLOYEE" />
<cf:enumerationValue name="ELECTED" />
<cf:enumerationValue name="VOLUNTEER" />
<cf:enumerationValue name="INDIVIDUAL" />
<cf:enumerationValue name="PRESIDENT" />
<cf:enumerationValue name="VICE_PRESIDENT" />
<cf:enumerationValue name="TREASURER" />
<cf:enumerationValue name="SECRETARY" />
<cf:enumerationValue name="BOARD_MEMBER" />
<cf:enumerationValue name="LEGAL_MEMBER" />
<cf:enumerationValue name="BY_LAW_MEMBER" />
<cf:enumerationValue name="ACCOUNT_INSPECTOR" />
<cf:enumerationValue name="RESELLER" />
<cf:enumerationValue name="OWNER" />
<cf:enumerationValue name="CONTRACTOR" />
<cf:enumerationValue name="GENERAL_CONTRACTOR" />
<cf:enumerationValue name="CONTRACTING_AUTHORITY" />
<cf:enumerationValue name="LESSOR" />
<cf:enumerationValue name="OTHER" />
<cf:enumerationValue name="MEMBER" />
</cf:enumeration>
<cf:enumeration name="enumStructureSkillTerritoryType" namespace="Example.Models.Contact.Structure" categoryPath="/Example.Models">
<cf:enumerationValue name="LOCAL" />
<cf:enumerationValue name="DEPARTEMENTAL" />
<cf:enumerationValue name="REGIONAL" />
<cf:enumerationValue name="NATIONAL" />
</cf:enumeration>
<cf:entity name="StructurePublicOrganization" baseTypeName="Example.Models.Contact.Structure.Structure" namespace="Example.Models.Contact.Structure" categoryPath="/Example.Models" storeName="ExampleStoreName">
<cf:property name="ReceiptNum" persistenceEnforce="true" />
</cf:entity>
</cf:project>
The generated SQL (note the extra AND in townLabel parameter)
CREATE PROCEDURE [Contact].[Contact_AdvancedSearchContactsTownLabel]
(
#firstname [nvarchar] (256) = NULL,
#name [nvarchar] (256) = NULL,
#groups [Contact].[cf_type_Contact_AdvancedSearchContactsTownLabel_2] READONLY,
#postalCode [nvarchar] (256) = NULL,
#townLabel [nvarchar] (256) = NULL,
#mail [nvarchar] (256) = NULL,
#townId [nvarchar] (max) = NULL,
#structureId [uniqueidentifier] = NULL,
#countryId [uniqueidentifier] = NULL,
#_orderBy0 [nvarchar] (64) = NULL,
#_orderByDirection0 [bit] = 0
)
AS
SET NOCOUNT ON
DECLARE #_c_groups int; SELECT #_c_groups= COUNT(*) FROM #groups
DECLARE #sql nvarchar(max), #paramlist nvarchar(max)
SELECT #sql=
'SELECT DISTINCT [Contact].[Contact].[Contact_Name], [Contact].[Contact].[Contact_Firstname], [Contact].[Contact].[Contact_Civility], [Contact].[Contact].[Contact_DateOfBirth], [Contact].[Contact].[Contact_Comment], [Contact].[Contact].[Contact_ContactId], [Contact].[Contact].[Contact_Address_AddressId], [Contact].[Contact].[Contact_TownOfBirthLabel], [Contact].[Contact].[Contact_TownIdOfBirth], [Contact].[Contact].[Contact_CountryIdOfBirth], [Contact].[Contact].[Contact_DepartmentIdOfBirth], [Contact].[Contact].[Contact_PostalCode], [Contact].[Contact].[Contact_CartePecheMemberId], [Contact].[Contact].[_trackLastWriteTime], [Contact].[Contact].[_trackCreationTime], [Contact].[Contact].[_trackLastWriteUser], [Contact].[Contact].[_trackCreationUser], [Contact].[Contact].[_rowVersion]
FROM [Contact].[Contact]
LEFT OUTER JOIN [Contact].[Address] ON ([Contact].[Contact].[Contact_Address_AddressId] = [Contact].[Address].[Address_AddressId])
LEFT OUTER JOIN [Contact].[StructureContact] ON ([Contact].[Contact].[Contact_ContactId] = [Contact].[StructureContact].[StructureContact_Contact_ContactId])
LEFT OUTER JOIN [Contact].[Address] [Address$1] ON ([Contact].[StructureContact].[StructureContact_Address_AddressId] = [Address$1].[Address_AddressId])
LEFT OUTER JOIN [Contact].[StructureContact_Groups_Group] ON ([Contact].[StructureContact].[StructureContact_StructureContactId] = [Contact].[StructureContact_Groups_Group].[StructureContact_StructureContactId])
LEFT OUTER JOIN [Contact].[Group] ON ([Contact].[StructureContact_Groups_Group].[Group_GroupId] = [Contact].[Group].[Group_GroupId])
LEFT OUTER JOIN [Contact].[Structure] ON ([Contact].[StructureContact].[StructureContact_Structure_StructureId] = [Contact].[Structure].[Structure_StructureId])
LEFT OUTER JOIN [Contact].[Address] [Address$2] ON ([Contact].[Contact].[Contact_Address_AddressId] = [Address$2].[Address_AddressId])
LEFT OUTER JOIN [Contact].[Contact_Groups_Group] ON ([Contact].[Contact].[Contact_ContactId] = [Contact].[Contact_Groups_Group].[Contact_ContactId])
LEFT OUTER JOIN [Contact].[Group] [Group$1] ON ([Contact].[Contact_Groups_Group].[Group_GroupId] = [Group$1].[Group_GroupId])
LEFT OUTER JOIN [Contact].[Address] [Address$3] ON ([Contact].[Contact].[Contact_Address_AddressId] = [Address$3].[Address_AddressId])
WHERE (((1 = 1) AND ((1 = 1) AND ((1 = 1) AND ((1 = 1) AND ((1 = 1) AND ((1 = 1) AND ((1 = 1) AND (1 = 1)))))))) AND (1 = 1))'
SELECT #paramlist = '#firstname nvarchar (256),
#name nvarchar (256),
#groups [Contact].[cf_type_Contact_AdvancedSearchContactsTownLabel_2] READONLY,
#postalCode nvarchar (256),
#townLabel nvarchar (256),
#mail nvarchar (256),
#townId nvarchar (max),
#structureId uniqueidentifier,
#countryId uniqueidentifier,
#_orderBy0 nvarchar (64),
#_orderByDirection0 bit'
IF #firstname IS NOT NULL
SELECT #sql = #sql + ' AND (([Contact].[Contact].[Contact_Firstname] LIKE ((''%'' + #firstname) + ''%'')))'
IF #name IS NOT NULL
SELECT #sql = #sql + ' AND (([Contact].[Contact].[Contact_Name] LIKE ((''%'' + #name) + ''%'')))'
IF #_c_groups > 0
SELECT #sql = #sql + ' AND (([Contact].[Group].[Group_Value] IN ((SELECT * FROM #groups)) OR [Group$1].[Group_Value] IN ((SELECT * FROM #groups))))'
IF #postalCode IS NOT NULL
SELECT #sql = #sql + ' AND ((([Contact].[Address].[Address_PostalCode] LIKE ((''%'' + #postalCode) + ''%'')) OR ([Address$1].[Address_PostalCode] LIKE ((''%'' + #postalCode) + ''%''))))'
IF #townLabel IS NOT NULL
SELECT #sql = #sql + ' AND ((([Address$2].[Address_TownLabel] LIKE ((''%'' + #townLabel) + ''%'')) OR (([Contact].[Address].[Address_TownLabel] LIKE ((''%'' + #townLabel) + ''%'')) OR ([Contact].[Address].[Address_TownId] IN ((SELECT [Item] FROM [dbo].cf_SplitString(#townId, nchar(1)))) OR [Contact].[Address].[Address_TownId] IN ((SELECT [Item] FROM [dbo].cf_SplitString(#townId, nchar(1))))))) AND ([Contact].[Address].[Address_TownLabel] LIKE ((''%'' + #townLabel) + ''%'')))'
IF #mail IS NOT NULL
SELECT #sql = #sql + ' AND ((([Address$3].[Address_Email] LIKE ((''%'' + #mail) + ''%'')) OR ([Contact].[Address].[Address_Email] LIKE ((''%'' + #mail) + ''%''))))'
IF #townId IS NOT NULL
SELECT #sql = #sql + ' AND (([Contact].[Address].[Address_TownId] IN ((SELECT [Item] FROM [dbo].cf_SplitString(#townId, nchar(1)))) OR [Contact].[Address].[Address_TownId] IN ((SELECT [Item] FROM [dbo].cf_SplitString(#townId, nchar(1))))))'
IF #structureId IS NOT NULL
SELECT #sql = #sql + ' AND (([Contact].[Structure].[Structure_StructureId] = #structureId))'
IF #countryId IS NOT NULL
SELECT #sql = #sql + ' AND ((([Contact].[Address].[Address_CountryId] = #countryId) OR ([Contact].[Address].[Address_CountryId] = #countryId)))'
SELECT #sql = #sql + ' ORDER BY [Contact].[Contact].[Contact_Name] ASC,[Contact].[Contact].[Contact_Firstname] ASC'
EXEC sp_executesql #sql, #paramlist,
#firstname,
#name,
#groups,
#postalCode,
#townLabel,
#mail,
#townId,
#structureId,
#countryId,
#_orderBy0,
#_orderByDirection0
RETURN
GO
EDIT 16/09/2016-possible workarounds found.
I found two possible workarounds:
First is to have a simpler search method with the rest of parameters (no townId, no townLabel), and to re-filter in memory with a LINQ mechanism.
Second is to go use generated code in a RAW method and adapt it to make it work the way we want.
Search methods are very tricky to generate. In fact, the producer must split the body of the method by parameters. Then it creates IF #param IS NOT NULL statement and combine them using an operator (by default AND). If you want to change this operator, you can add the following xml attribute at the method:
<cf:method cfps:searchOperation="OR" ... />
If you don't have too many arguments (1 or 2) you can use a LOAD method with nullable parameters:
<cf:method name="LoadNullable" body="LOAD(string text1, string text2) WHERE Name = #text1 AND Name = #text2">
<cf:parameter nullable="True" name="text1" modelNullable="False" />
</cf:method>
The generated code looks like:
CREATE PROCEDURE [dbo].[Customer_LoadNullable]
(
#text1 [nvarchar] (256) = NULL,
#text2 [nvarchar] (256)
)
AS
SET NOCOUNT ON
IF(#text1 IS NULL)
BEGIN
SELECT [Customer].[Customer_Id], [Customer].[Customer_Name]
FROM [Customer]
WHERE ([Customer].[Customer_Name] = #text2)
END
ELSE
BEGIN
SELECT [Customer].[Customer_Id], [Customer].[Customer_Name]
FROM [Customer]
WHERE (([Customer].[Customer_Name] = #text1) AND ([Customer].[Customer_Name] = #text2))
END
This way you don't have any issue with the OR and AND, but this is not suitable for methods with many nullable parameters.

How to pass parameter in Form Scope for REST services in ColdFusion?

Today while working with ColdFusion 10 REST, I got an issues. I am not sure how to pass data to a REST service in FORM scope.
Here is my REST enabled CFC,
<cfcomponent rest="true" restpath="/crudService" >
<cfset variable.myQuery = queryNew("Id,Name","Integer,Varchar",[[1,"Test1"],[2,"Test2"],[3,"Test3"]] )>
<cffunction name="getHandlerJSONForm" access="remote" httpmethod="GET" restpath="/formtest" returntype="query" produces="application/xml">
<cfargument name="customerID" required="true" restargsource="Form" type="numeric" >
<cfquery dbtype="query" name="local.qryGetUserName">
SELECT Name
FROM variable.myQuery
WHERE Id = <cfqueryparam cfsqltype="cf_sql_integer" value="#customerID#">
</cfquery>
<cfreturn local.qryGetUserName>
</cffunction>
</cfcomponent>
Here is the CFM code, calling the REST service,
<cfset restInitApplication("E:\Local Workspace\cfcs\rest","myfirstrest")>
<cfhttp url="http://cflocal.com/rest/myfirstrest/crudService/formtest" method="get" >
<cfhttpparam type="header" name="Content-Type" value="application/x-www-form-urlencoded" >
<cfhttpparam type="formfield" name="customerID" value="1" >
</cfhttp>
<cfdump var="#cfhttp#">
In StatusCode I am getting 500 Exception obtaining parameters ?
Please suggest whats going wrong here.

Coldfusion REST - Serialize Array of CFC

Hi I'm trying to serialize an array of CFCs from one of my REST endpoints. I found this Example: Array of CFC Serialization in the Adobe Help, which pretty much is exactly what I want to do (I can post some code if necessary) Yet when I try to use returnType="myCFC[]" it fails with:
"Message":"array element type mismatch"
The strange thing is, if I instantiate the same object and call the method from a .cfm file, the cfdump shows the array of objects with data as expected. But from my AJAX call, the object's property values are all null. However, if I use return serializeJSON(myArrayOfCFCs) the properties have data. But I don't want to have to do that because it will negate the use of content negotiation.
Just curious if anyone has gotten this to work.
update:
<cffunction name="getPatient" access="remote" httpmethod="GET" returntype="Patient[]" produces="text/json" restpath="/{PatientId}">
<cfargument name="PatientId" type="numeric" required="true" restargsource="Path" />
<cfset local.response = ArrayNew(1) />
<cfset local.patient = getPatientGatewayObject().getPatient(PatientId)>
<cfset local.patientObject = createObject("component", "Patient").init(argumentCollection=queryRowToStruct(local.patient)) />
<cfset arrayAppend(local.response, local.patientObject) />
<cfreturn local.response />
</cffunction>
This works, but not what I want in the end:
<cffunction name="getPatient" access="remote" httpmethod="GET" returntype="Patient" produces="text/json" restpath="/{PatientId}">
<cfargument name="PatientId" type="numeric" required="true" restargsource="Path" />
<cfset local.response = ArrayNew(1) />
<cfset local.patient = getPatientGatewayObject().getPatient(PatientId)>
<cfset local.patientObject = createObject("component", "Patient").init(argumentCollection=queryRowToStruct(local.patient)) />
<cfset arrayAppend(local.response, local.patientObject) />
<cfreturn serializeJSON(local.response) />
</cffunction>

How do I get the value of the Discriminator Column from an Entity Framework Entity

I've got a project in written in the EDM. Does anyone know how to get the value of the discriminator column from an entity in a TPH inheritance tree? I can't add the property to the entity. Is there any other way to get the value?
Thanks,
Roy
There is a simple way to solve the problem for the DBMS that suports updatable views.
You can simply create a view or a Defining Query having an additional discriminator column.
The original column should be mapped to the class property. In case when DBMS does not support the updatable views you can use Defining Query and then map stored procedures for Insert/Update/Delete operations.
Here is an example for Oracle database:
SQL:
CREATE TABLE TEST.TPH_TABLE (
ID NUMBER(9),
COLUMN_A VARCHAR2(20),
COLUMN_B VARCHAR2(20),
BASE_COLUMN VARCHAR2(20),
CONSTRAINT PK_TPH_TABLE PRIMARY KEY (ID)
);
EDMX:
<edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx">
<!-- EF Runtime content -->
<edmx:Runtime>
<!-- SSDL content -->
<edmx:StorageModels>
<Schema Namespace="Model1.Store" Alias="Self" Provider="Devart.Data.Oracle" ProviderManifestToken="ORA" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2006/04/edm/ssdl">
<EntityContainer Name="Model1StoreContainer">
<EntitySet Name="TPH_TABLE" EntityType="Model1.Store.TPH_TABLE" >
<DefiningQuery>
SELECT ID, BASE_COLUMN, COLUMN_A, COLUMN_B,
CASE WHEN COLUMN_A IS NOT NULL THEN '1' ELSE NULL END AS "IS_TABLE_A"
FROM TPH_TABLE
</DefiningQuery>
</EntitySet>
</EntityContainer>
<EntityType Name="TPH_TABLE">
<Key>
<PropertyRef Name="ID" />
</Key>
<Property Name="ID" Type="int" Nullable="false" />
<Property Name="BASE_COLUMN" Type="VARCHAR2" MaxLength="20" />
<Property Name="COLUMN_A" Type="VARCHAR2" MaxLength="20" />
<Property Name="COLUMN_B" Type="VARCHAR2" MaxLength="20" />
<Property Name="IS_TABLE_A" Type="VARCHAR2" MaxLength="1" />
</EntityType>
</Schema>
</edmx:StorageModels>
<!-- CSDL content -->
<edmx:ConceptualModels>
<Schema Namespace="Model1" Alias="Self" xmlns="http://schemas.microsoft.com/ado/2006/04/edm">
<EntityContainer Name="Entities">
<EntitySet Name="TPH_TABLE" EntityType="Model1.TPH_TABLE" />
</EntityContainer>
<EntityType Name="TPH_TABLE" Abstract="true">
<Key>
<PropertyRef Name="ID" />
</Key>
<Property Name="ID" Type="Int32" Nullable="false" />
<Property Name="BASE_COLUMN" Type="String" MaxLength="20" Unicode="true" FixedLength="false" />
</EntityType>
<EntityType Name="TABLE_A" BaseType="Model1.TPH_TABLE" >
<Property Name="COLUMN_A" Type="String" Nullable="true" />
</EntityType>
<EntityType Name="TABLE_B" BaseType="Model1.TPH_TABLE" >
<Property Name="COLUMN_B" Type="String" Nullable="true" />
</EntityType>
</Schema>
</edmx:ConceptualModels>
<!-- C-S mapping content -->
<edmx:Mappings>
<Mapping Space="C-S" xmlns="urn:schemas-microsoft-com:windows:storage:mapping:CS">
<EntityContainerMapping StorageEntityContainer="Model1StoreContainer" CdmEntityContainer="Entities">
<EntitySetMapping Name="TPH_TABLE">
<EntityTypeMapping TypeName="Model1.TABLE_A">
<MappingFragment StoreEntitySet="TPH_TABLE">
<ScalarProperty Name="ID" ColumnName="ID" />
<ScalarProperty Name="BASE_COLUMN" ColumnName="BASE_COLUMN" />
<ScalarProperty Name="COLUMN_A" ColumnName="COLUMN_A" />
<Condition ColumnName="IS_TABLE_A" Value="1" />
</MappingFragment>
</EntityTypeMapping>
<EntityTypeMapping TypeName="Model1.TABLE_B">
<MappingFragment StoreEntitySet="TPH_TABLE">
<ScalarProperty Name="ID" ColumnName="ID" />
<ScalarProperty Name="BASE_COLUMN" ColumnName="BASE_COLUMN" />
<ScalarProperty Name="COLUMN_B" ColumnName="COLUMN_B" />
<Condition ColumnName="IS_TABLE_A" IsNull="true" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
</EntityContainerMapping>
</Mapping>
</edmx:Mappings>
</edmx:Runtime>
<!-- EF Designer content (DO NOT EDIT MANUALLY BELOW HERE) -->
<edmx:Designer xmlns="http://schemas.microsoft.com/ado/2007/06/edmx">
<edmx:Connection>
<DesignerInfoPropertySet>
<DesignerProperty Name="MetadataArtifactProcessing" Value="EmbedInOutputAssembly" />
</DesignerInfoPropertySet>
</edmx:Connection>
<edmx:Options>
<DesignerInfoPropertySet>
<DesignerProperty Name="ValidateOnBuild" Value="true" />
</DesignerInfoPropertySet>
</edmx:Options>
<!-- Diagram content (shape and connector positions) -->
<edmx:Diagrams>
<Diagram Name="Model4">
<EntityTypeShape EntityType="Model1.TPH_TABLE" Width="1.5" PointX="3" PointY="0.5" Height="1.2636116536458335" IsExpanded="true" />
<EntityTypeShape EntityType="Model1.TABLE_A" Width="1.5" PointX="1.75" PointY="2.75" Height="1.099264322916667" />
<EntityTypeShape EntityType="Model1.TABLE_B" Width="1.5" PointX="4.25" PointY="2.75" Height="1.099264322916667" />
<InheritanceConnector EntityType="Model1.TABLE_B" ManuallyRouted="false">
<ConnectorPoint PointX="4.375" PointY="1.7636116536458335" />
<ConnectorPoint PointX="4.375" PointY="2.75" />
</InheritanceConnector>
<InheritanceConnector EntityType="Model1.TABLE_A" ManuallyRouted="false">
<ConnectorPoint PointX="3.125" PointY="1.7636116536458335" />
<ConnectorPoint PointX="3.125" PointY="2.75" />
</InheritanceConnector></Diagram></edmx:Diagrams>
</edmx:Designer>
</edmx:Edmx>