I need the following condition (in SQL) to fill a specific field in my resultset:
CASE
WHEN M.ID_ENTIDAD = m.ID_ENTIDAD_VENTA then EC.CLAVE_ENTIDAD
END AS Contraparte }
If I use
var contraparte = Projections.Conditional(
Restrictions.EqProperty("EntidadOwner", "EntidadVenta"),
Projections.Property("enc.CvePrincipalMiembro"),
null);
That return an error.
Also if I use:
*var contraparte = Projections.Conditional(
Restrictions.EqProperty("EntidadOwner", "EntidadVenta"),
Projections.Property("enc.CvePrincipalMiembro"),
Projection.Constant(a constant value);*
Apparently it is not possible to use this Conditional without ELSE part. that is nhibernate can not generate CASE without ELSE part.
It is possible to do this?? Please help me!!!
Thanks
Ok. I found self the response.
I took two actions:
One, add the following dummy field in the map class used in your query:
Map(x => x.Dummy).Nullable().Formula("NULL");
Second: I modified the conditional projection with the following code:
var contraparte = Projections.Conditional(
Restrictions.EqProperty("EntidadOwner", "EntidadVenta"),
Projections.Property("enc.CvePrincipalMiembro"),
Projections.Property("Dummy"));
That was all! I hope that this help another people with the same problem.
Related
I am trying to order my table, but this ordering is not working correctly.
Example:
let dataArr = [3257,327,313,315,312,316,317,321,326,302];
I am using => _.orderBy(dataArr, ['number'], ['asc']) => [302,312,313,315,316,317,321,3257,326,327]
Why it isn't return like this [302,312,313,315,316,317,321,326,327,3257]?
How can I figure this problem out?
You can use like this,
let dataArr = [3257,327,313,315,312,316,317,321,326,302];
_.orderBy(dataArr)
This will return your expected result. It is a simple array so you don't need to give it as a number type or order[asc/desc]. By default, it takes asc order.
You are missing the "iteratees" argument. Since numbers don't have an "asc" property, this call does nothing. You should use the _.identity iterattee there:
_.orderBy(dataArr, [_.identity], ['asc'])
// Here -----------^
I am modifying the SalesConfirmDP class and trying to add the CustVendExternalItem.ExternalItemTxt field into a new field I have created.
I have tried a couple of things but I do not think my syntax was correct i.e I declare the CustVendExternalItem table in the class declaration. But then when I try to insert CustVendExternalItem.ExternalItemTxt into my new field, it does not populate, I guess there must be a method which I need to include?
If anyone has any suggestion it would be highly appreciated.
Thank you in advance.
private void setSalesConfirmDetailsTmp(NoYes _confirmTransOrTaxTrans)
{
DocuRefSearch docuRefSearch;
// Body
salesConfirmTmp.JournalRecId = custConfirmJour.RecId;
if(_confirmTransOrTaxTrans == NoYes::Yes)
{
if (printLineHeader)
{
salesConfirmTmp.LineHeader = custConfirmTrans.LineHeader;
}
else
{
salesConfirmTmp.LineHeader = '';
}
salesConfirmTmp.ItemId = this.itemId();
salesConfirmTmp.Name = custConfirmTrans.Name;
salesConfirmTmp.Qty = custConfirmTrans.Qty;
salesConfirmTmp.SalesUnitTxt = custConfirmTrans.salesUnitTxt();
salesConfirmTmp.SalesPrice = custConfirmTrans.SalesPrice;
salesConfirmTmp.DlvDate = custConfirmTrans.DlvDate;
salesConfirmTmp.DiscPercent = custConfirmTrans.DiscPercent;
salesConfirmTmp.DiscAmount = custConfirmTrans.DiscAmount;
salesConfirmTmp.LineAmount = custConfirmTrans.LineAmount;
salesConfirmTmp.CurrencyCode = custConfirmJour.CurrencyCode;
salesConfirmTmp.PrintCode = custConfirmTrans.TaxWriteCode;
if (pdsCWEnabled)
{
salesConfirmTmp.PdsCWUnitId = custConfirmTrans.pdsCWUnitId();
salesConfirmTmp.PdsCWQty = custConfirmTrans.PdsCWQty;
}
**salesConfirmTmp.ExternalItemText = CustVendExternalItem.ExternalItemTxt;**
if ((custFormletterDocument.DocuOnConfirm == DocuOnFormular::Line)
|| (custFormletterDocument.DocuOnConfirm == DocuOnFormular::All))
{
docuRefSearch = DocuRefSearch::newTypeIdAndRestriction(custConfirmTrans,
custFormletterDocument.DocuTypeConfirm,
DocuRestriction::External);
salesConfirmTmp.Notes = Docu::concatDocuRefNotes(docuRefSearch);
}
salesConfirmTmp.InventDimPrint = this.printDimHistory();
Well, AX cannot guess which record you need, there is a helper class CustVendExternalItemDescription to deal with it:
boolean found;
str externalItemId;
...
[found, externalItemId, salesConfirmTmp.ExternalItemText] = CustVendExternalItemDescription::findExternalItemDescription(
ModuleCustVend::Cust,
custConfirmTrans.ItemId,
custConfirmTrans.inventDim(),
custConfirmJour.OrderAccount,
CustTable::find(custConfirmJour.OrderAccount).CustItemGroupId);
The findExternalItemDescription method returns more information than you need here, but you have to define variables to store it anyway.
Well, the steps to solve this problem are fairly easy and i will try to give you a step by step approach how to solve this problem.
1) Are you initialising CustVendExternalItem properly? Make a record of the same and initialise it as Jan has shown above, then debug your code and see if the value is being initialised in your DP class.
2)If your value is being initialised correctly, but it is not showing up in the report design there can be multiple issues such as:
Overlapping of text boxes.
Insufficient space for the given field
Some report parameter/property not being set correctly which causes
your value not to show up on the report.
Check these one by one and you should end up arriving towards a solution
In RavenDB (build 2330) I'm trying to order my results by the string length of one of the indexed terms.
var result = session.Query<Entity, IndexDefinition>()
.Where(condition)
.OrderBy(x => x.Token.Length);
However the results look to be un-sorted. Is this possible in RavenDB (or via a Lucene query) and if so what is the syntax?
You need to add a field to IndexDefinition to order by, and define the SortOption to Int or something more appropriate (however you don't want to use String which is default).
If you want to use the Linq API like in your example you need to add a field named Token_Length to the index' Map function (see Matt's comment):
from doc in docs
select new
{
...
Token_Length = doc.TokenLength
}
And then you can query using the Linq API:
var result = session.Query<Entity, IndexDefinition>()
.Where(condition)
.OrderBy(x => x.Token.Length);
Or if you really want the field to be called TokenLength (or something other than Token_Length) you can use a LuceneQuery:
from doc in docs
select new
{
...
TokenLength = doc.Token.Length
}
And you'd query like this:
var result = session.Advanced.LuceneQuery<Entity, IndexDefinition>()
.Where(condition)
.OrderBy("TokenLength");
I'm using LINQ towards my MSSQL database. I have the TypeOfMetaData-table, the UserMetaData-table and the MetaDataHasType-table that has foreign-keys from the TypeOfMetaData- and the UserMetaData-table. What I need to do a method to get all MetaData and Types and return them. The problem is that I don't know what kind of return value I should use to be able to match the correct rows together.
Thanks for the help,
wardh
You could use an Anonymous Type (var) to store the result:
var result =
yourDataContext
.UserMetaData_Table
.Select(
userMetaData =>
new
{
UserMetaData = userMetaData,
Types = userMetaData.MetaDataHasTypes.Select(types => types.TypeOfMetaData),
})
.ToArray();
If this isn't what you want, could you update you question to with an example of the data context and the classes you have and what you have tried so far.
I have a problem using QBE with NHibernate.
Here's a sample code:
Person person = new Person();
person.FirstName = "e";
using (ISession session = SessionFactory.CreateSession())
{
Example example = Example.Create(person).ExcludeProperty("DateOfBirth").EnableLike().IgnoreCase();
IList<Person> people = session.CreateCriteria<Person>().Add(example).List<Person>();
return people;
}
What I expect is that this example & criteria will return all persons whose first name starts with an "e". BUT, to accomplish this I had to insert escape character in the example object's property. Like this:
person.FirstName = "e%";
With this modification, query returns the desired results.
Shouldn't the "EnableLike" take care of this?
What am I doing wrong?
Thanks!
im not an expert, but seems you need to put a matchmode in your enablelike(), just like:
Example.Create(person).ExcludeProperty("DateOfBirth")
.EnableLike(NHibernate.Expression.MatchMode.Start)
.IgnoreCase();
the matchmode can be:start, end,exact and anywhere
hope this help