Composite Key WITH Operator IN and SubQuery [closed] - c#

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)

Related

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
}

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
);

How to perform innner Join on Five Tables using Linq [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
gameScheduling db = new gameScheduling();
var query = from c in db.tblgroupDetail
join g in db.groups on c.GroupId equals g.GroupId
join t in db.Tournaments on c.TournamentId equals t.tournamentId
and so on......
select new {c.Name etc etc}
I have an error on join plz some useful suggestions.
Are the types of your expression variables the same?
E.g.: are c.GroupId and g.GroupId both int or is one of them of type byte?
The types of the variables in your expressions must be of the same type if you want to compare them with each other.
I think you have to use .Value with the field name in the select clause....
I did one similar scenario it may help you please check below link
Join two data table and return new table

Linq join with conversion [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 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()

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