C# SQL Statement transformed TO LINQ how can i translate this statement to a working linq
Tag : chash , By : picamiolo
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Make sure you reference System.Data.DataSetExtensions, and use the AsEnumerable() method to use LINQ to DataSets. var myTable1 = new [] {
new { CID = "123", AID = 345, Data = 32323, Status = 1, Language = "EN"},
new { CID = "231", AID = 123, Data = 11525, Status = 2, Language = "EN"},
new { CID = "729", AID = 513, Data = 15121, Status = 1, Language = "ANY"},
new { CID = "231", AID = 123, Data = 54421, Status = 2, Language = "EN"}}
.ToDataTable().AsEnumerable();
var myTable2 = new [] {
new { CID = "512", AID = 513, Data = 32323, Status = 1, Language = "ANY"},
new { CID = "444", AID = 123, Data = 11525, Status = 2, Language = "BLAH"},
new { CID = "222", AID = 333, Data = 15121, Status = 1, Language = "ANY"},
new { CID = "111", AID = 345, Data = 54421, Status = 2, Language = "EN"}}
.ToDataTable().AsEnumerable();
var myTable3 = new [] {
new { CID = "888", AID = 123, Data = 32323, Status = 2, Language = "EN"},
new { CID = "494", AID = 333, Data = 11525, Status = 1, Language = "FR"},
new { CID = "202", AID = 513, Data = 15121, Status = 1, Language = "EN"},
new { CID = "101", AID = 345, Data = 54421, Status = 2, Language = "ANY"}}
.ToDataTable().AsEnumerable();
var q = from p in myTable1
join b in myTable2.Union(myTable3) on p.Field<int>("AID") equals b.Field<int>("AID")
where (b.Field<string>("Language") == "EN" || b.Field<string>("Language") == "ANY") && b.Field<int>("Status") == 1
select new
{
CID = p.Field<string>("CID"),
B_AID = p.Field<int>("AID"),
P_AID = b.Field<int>("AID"),
Data = b.Field<int>("Data"),
Status = b.Field<int>("Status"),
Language = b.Field<string>("Language")
};
var table = q.ToDataTable();
|
Linq to NHibernate and Dynamic LINQ - query caching not working
Tag : linq , By : socurious
Date : March 29 2020, 07:55 AM
I hope this helps you . Ok, I know what is the reason. Dynamic Linq doesn't use Parameter Names in Linq Expressions. E.g. if I want to sort using lambda statemant, I write: query.OrderBy(item => item.Name)
query.OrderBy("Name")
query.OrderBy( => .Name)
if (parameters.Length == 1 && String.IsNullOrEmpty(parameters[0].Name))
if (parameters.Length == 1 && (parameters[0].Name == "it" || String.IsNullOrEmpty(parameters[0].Name)))
Expression.Parameter(source.ElementType, "")
Expression.Parameter(source.ElementType, "it")
|
How to write a statement that generates a LIKE T-SQL statement in System.Linq.Dynamic
Tag : chash , By : Tamizhvendan
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , System.Linq.Dynamic translates your text to regular LINQ expressions, and there is no concept of "LIKE" there. How would you write your like in regular LINQ? Something like that: ctx.Entity.Where(c => c.Description.StartsWith("test"));
// @0 is first parameter, which is "test" in this case
ctx.Entity.Where("Description.StartsWith(@0)", "test");
ctx.Entity.Where("Description.StartsWith(\"test\")");
|
Linq to excel not working , when upgrading .net core 2.1 to .net core 2.2
Date : March 29 2020, 07:55 AM
this will help I think linq to excel don't work in .net core 2.2. so better to use EPPlus package. Download EPPlus.Core from nuget package Dictionary<object, string> leadExcelViewModels = new Dictionary<object, string>();
using (ExcelPackage package = new ExcelPackage(file))
{
ExcelWorksheet workSheet = package.Workbook.Worksheets[1];
int totalRows = workSheet.Dimension.Rows;//get total rows counts of excel file
int totalColumns = workSheet.Dimension.Columns;// get total columns count of excel file.
if (totalRows > 1)
{
for (int i = 2; i < totalRows; i++)
{
leadExcelViewModels = new Dictionary<object, string>();
leadModel = new YourViewModel();
for (int j = 1; j <= totalColumns; j++)
{
if (workSheet.Cells[i, j].Value != null)
leadExcelViewModels.Add(workSheet.Cells[1, j].Value, workSheet.Cells[i, j].Value.ToString());
else
leadExcelViewModels.Add(workSheet.Cells[1, j].Value, "0");
}
var js = JsonConvert.SerializeObject(leadExcelViewModels);
leadModel = JsonConvert.DeserializeObject<YourViewModel>(js);
// bind each leadModel to List of your YourViewModel list.
}
}
}
|
EF Core 2.2 LINQ query not working in EF Core 3.0
Date : October 01 2020, 03:00 PM
|