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
);
Related
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
}
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
I am trying to sort my customers by their last order by using linq.
_list = _data.OrderBy(adress => adress.LastOrder.Date);
My Problem here is, that for some customers the LastOrder is NULL
How can I solve this problem?
Try this:
_list = _data.OrderBy(adress =>
adress.LastOrder == null
? DateTime.MaxValue
: adress.LastOrder.Date);
You need to choose between DateTime.MaxValue and DateTime.MinValue depending on how you want to order null items.
You have to handle the null case:
var orderedByLastOrder = _data
.OrderBy(x => x.LastOrder == null ? DateTime.MinValue : x.LastOrder.Date);
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
How can I do a link who have a value on the where that I have to transform into a string
Like this example:
Fund.ObjectName = context.CR_TASK.First(a => Convert.ToString(a.TASK_NO) == item.DATA_TEXT).TASK_TITLE;
I would use FirstOrDefault to assign null if no item matches:
Fund.ObjectName = context.CR_TASK
.Where(a => a.TASK_NO.ToString() == item.DATA_TEXT)
.Select(a => a.TASK_TITLE)
.FirstOrDefault();
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()
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)