Linq join with conversion [closed] - c#

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am doing a kind of Join in my MVC application by using LINQ as,
var temp= (from enumeration in db.Enumerations
join cust in db.Customers on Convert.ToInt32(enumeration.Value) equals cust.lkpStatus
where (cust.ID==data.ID &&
enumeration.EnumerationTypeID.Contains("Customer.lkpStatus") )
select enumeration).FirstOrDefault();
In this I have got a Problem on Join is that "enumeration.Value" is a string value and " cust.lkpStatus" is an int.
So how can be the query to do joining by using the LINQ. Please suggest some LINQ query in this scenario.

try with SqlFunctions.StringConvert
join cust in db.Customers on
enumeration.Value equals SqlFunctions.StringConvert((decimal) cust.lkpStatus).Trim()

Related

Need Help Converting SQL Query to LINQ-to-SQL [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 days ago.
Improve this question
the query is:
SELECT DISTINCT TOP 10 COUNT( pp.Id), cd.Country,cd.State, pp.Id,cd.Email,CAST(pp.CreateDate AS DATE) AS paymentdate FROM Payments pp
JOIN cdTbl cd
ON pp.Id = cd.Id
WHERE pp.CreateDate IS NOT NULL AND CAST(pp.CreateDate AS DATE) = CAST(GETDATE() AS DATE)
GROUP BY pp.Id, cd.Email,CAST(pp.CreateDate AS DATE),cd.Country,cd.State
HAVING COUNT( pp.Id) > 1 AND cd.Email IS NOT NULL
ORDER BY CAST(pp.CreateDate AS DATE) DESC
Thanks

How can I implement SQL statement to LINQ in MVC? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Good day
I need to interpret the following SQL to LINQ.
select
t1.req_no,
t1.seq_no,
t1.quantity,
t1.uom,
t1.item_name,
t2.event_date
from tb_cs_test t1, tb_cs_test2 t2 where (t1.req_no = 1 and t2.req_no = 1 );
I use MVC and with this SQL Statement i need to throw the requested fields based on the condition that I put
Thanks
You can do that with a JOIN:
from t1 in tb_cs_test
join t2 in tb_cs_test2
on t1.req_no equals t2.req_no
where t1.req_no = 1
select new {
t1.req_no,
t1.seq_no,
t1.quantity,
t1.uom,
t1.item_name,
t2.event_date
}

Composite Key WITH Operator IN and SubQuery [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have this inner join and I'm using LINQ to make my queries, how can I write this query with LINQ, I was seeking it on internet but I cant find something like.
INNER JOIN e210mvp mvp
ON mvp.codemp IN (1 , 2)
AND mvp.codlot = dls.codlot
AND mvp.datmov = (SELECT MIN(min.datmov)
FROM e210mvp min
WHERE min.codemp = 1
AND min.codlot = mvp.codlot)
Thank you!
Leave the equality tests in the join and move the non-equality tests to where. Note that the equality tests must involve the left hand side (or an expression involving it) equals the right hand side (or an expression involving it). Since you have mvp on both sides of the sub-select test, you can't leave it in the join operation.
join mvp in e210mvp on dls.codlot equals mvp.codlot
where new[] { 1, 2}.Contains(mvp.codemp) &&
mvp.datmov == e210mvp.Where(min => min.codemp == 1 && min.codlot == mvp.codlot).Min(min => min.datmov)

What is the meaning of the mentioned query? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
If I had the table "CustomerDetails" than what is the below query explains??
var details = (from data in entity.CustomerDetails where (data.CustomerId == CustId && data.CustomerProjectID == CustProjId) select data).FirstOrDefault();
Share the exact meaning. Thanks in advance.
That query selects the data from the CustomerDetails table where the CustomerId equals the given CustId and the CustomerProjectID equals the given CustProjId. It then returns the first element from the set that returns.
I personally find it easier to use LINQ Expressions like so:
var details = entity.CustomerDetails
.FirstOrDefault(cust =>
cust.CustomerId == CustId &&
cust.CustomerProjectID == CustProjId
);

Outer apply in linq to sql [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
What's the linq to sql translation for this query
SELECT *
FROM MasterTable AS [t0]
Outer APPLY UfnGetDetail([t0].x, [t0].y, z) AS [t2]
...
Ok, it works with something like this
var query = from mt in db.MasterTable
let detailResult = db.UfnGetDetail(mt.x, mt.y, z).SingleOrDefault()...
Have you tried this:
from mt in dc.MasterTable
select dc.UfnGetDetail (mt.x, mt.y)

Categories