Showing posts with label linq. Show all posts
Showing posts with label linq. Show all posts

Thursday, November 5, 2009

Changes with a list

Inserting from the entity with a list.


foreach(ListItem itemlist in MyListBox.Items)
{
db.MyEntities.InsertOnSubmit(new MyEntity()
{
Id = variableId,
name = itemlist.Value
});
}

with a child:

foreach (ListItem col in SListBox.Items)
{
newentityMaster.Childentity.Add(new Childentity {
FilterId = newfilter.id,
ColumnName = col.Value,

});
}





getting my changes performed (DML, insert, delete, updates).

db.GetChangeSet().Inserts

Monday, November 2, 2009

order by in LINQ (basic example)

I have a table of filters from wich I want to get my last ID inserted , so I thought that I would sort in descending first and get the first element of the list.

Here's how to do a simple task like this.


var firstFilter = db.Filters.OrderByDescending(f => f.id).FirstOrDefault();






Tuesday, October 13, 2009

Oracle 10g with C# & asp.net

Now I'm trying to use Entity Framework to connect to an Oracle database with C#. Will see how it goes with this ad and free spacing.

Tools to be used for the test.

- Oracle 10g Express.

- Visual Studio.Net

Thursday, October 1, 2009

Linq with Outer Join, Ternary and orderby with linq

var query = from lfp in db.LogFundingPrograms
join rc in db.RefCycles on lfp.CycleId equals rc.CycleId
into JoinedRc
from rc in JoinedRc.DefaultIfEmpty()
join rf in db.RefFrequencies on lfp.Frequency equals rf.FrequencyId
orderby lfp.LogFundingId descending
select new
{
lfp.LogFundingId,
lfp.LogActionId,
lfp.FundingId,
lfp.FundingCode,
lfp.InstrumentCode,
LogActionDescription = lfp.RefLogAction.Description,
lfp.ApplicableDate,
lfp.Description,
rf.Frequency,
lfp.RollOverDay,
CycleDesc = lfp.CycleId != null ? rc.CycleDesc : "",
lfp.CCY,
lfp.CycleId,
lfp.IsConfirmed,
lfp.LastUser,
lfp.LastModified
};

as you can see the CycleDesc comes with a empty string if the CycleId doesn't bring a value since can be null.

Friday, September 4, 2009

traduciendo de vb for aplications a t-sql (ver. 1)

el query de la macro sin el valor de cadena que nos enviand en el texto.


qry = " SELECT GLProcessEntry.ProcessEntryId, GLAccount.MethodId, GLAccount.AccountId, GLAccount.OffSetAccountId,GLProcessEntryDetail.CcyAmount, "
qry = qry & " GLProcessEntryDetail.CADAmount, PeriodCcyRate.Quote, Round([CCyAmount]*[Quote]-[CADAmount],2) AS EntryAmount "
qry = qry & " FROM CfgCieMethodQuoteStatus,GLAccount,GLProcessEntry,GLProcessEntryDetail,PeriodCcyRate "
qry = qry & " WHERE GLProcessEntry.ProcessEntryId = GLProcessEntryDetail.ProcessEntryId "
qry = qry & " AND GLAccount.CieId = GLProcessEntry.CieId "
qry = qry & " AND GLAccount.AccountId = GLProcessEntryDetail.AccountId "
qry = qry & " AND GLAccount.CCy = PeriodCcyRate.Ccy "
qry = qry & " AND GLProcessEntry.PeriodId = PeriodCcyRate.PeriodId "
qry = qry & " AND CfgCieMethodQuoteStatus.QuoteStatusId = PeriodCcyRate.QuoteStatusId "
qry = qry & " AND CfgCieMethodQuoteStatus.MethodId = GLAccount.MethodId "
qry = qry & " AND CfgCieMethodQuoteStatus.CieId = GLAccount.CieId "
qry = qry & " AND GLProcessEntry.ProcessEntryId=" & ProcessEntryId
qry = qry & " AND GLAccount.MethodId=" & MethodId
If MethodId = 1 Then
qry = qry & " AND GLPRocessEntryDetail.AmountTypeId = 0 "
qry = qry & " AND ((Round([CCyAmount]*[Quote]-[CADAmount],2))<>0)"

Else
qry = qry & " AND GLPRocessEntryDetail.AmountTypeId = 1 "
qry = qry & " AND ((Round([CCyAmount]*[Quote]-[CADAmount],2))<>0)"
End If


------
la traduccion al t- sql

SELECT GLProcessEntry.ProcessEntryId, GLAccount.MethodId, GLAccount.AccountId, GLAccount.OffSetAccountId,GLProcessEntryDetail.CcyAmount,
GLProcessEntryDetail.CADAmount, PeriodCcyRate.Quote, Round([CCyAmount]*[Quote]-[CADAmount],2) AS EntryAmount
FROM CfgCieMethodQuoteStatus
INNER JOIN PeriodCcyRate on CfgCieMethodQuoteStatus.QuoteStatusId = PeriodCcyRate.QuoteStatusId
INNER JOIN GLAccount ON CfgCieMethodQuoteStatus.MethodId =GLAccount.MethodId
INNER JOIN GLProcessEntryDetail ON GLAccount.AccountId=GLProcessEntryDetail.AccountId
INNER JOIN RefCompany ON RefCompany.CieId = CfgCieMethodQuoteStatus.CieId
INNER JOIN RefDivision ON GLAccount.DivisionId = RefDivision.DivisionId
INNER JOIN GLProcessEntry ON GLProcessEntry.PeriodId = PeriodCcyRate.PeriodId
AND GLProcessEntry.ProcessEntryId = GLProcessEntryDetail.ProcessEntryId
WHERE GLPRocessEntryDetail.AmountTypeId = 0
and GLProcessEntry.ProcessEntryId = 169
AND GLAccount.MethodId = 1
and GLProcessEntryDetail.CADAmount = 0