|
|
var list1 = new List<ItemOne>
{
new ItemOne {IDItem = 1, OneProperty = "1"},
new ItemOne {IDItem = 2, OneProperty = null},
new ItemOne {IDItem = 3, OneProperty = "3"},
new ItemOne {IDItem = 4, OneProperty = "4"}
};
var list2 = new List<ItemTwo>
{
new ItemTwo {IDItem = 2, TwoProperty = "2"},
new ItemTwo {IDItem = 3, TwoProperty = "3"},
};
var query = list1.Join(list2, l1 => l1.IDItem, l2 => l2.IDItem, (l1, l2) =>
{
l1.OneProperty = l2.TwoProperty;
return l1;
});
see the above code where two list join and updating first list's one property called OneProperty by second list property called TwoProperty
how to do the same with LINQ normal syntax ? like below onevar data = (from a in list1
join b in list2
on a.IDItem equals b.IDItem into c
from d in c.DefaultIfEmpty()
select new
{
a.OneProperty=(d==null ? string.Empty : d.TwoProperty)
}).ToList();
in the above code i have not used JOIN function rather use join keyword. now tell how to customize my above code to update one property value of list1 by another property value from list2.
please share code or customize my code to work. thanks
|
|
|
|
|
Mou_kol wrote: how to do the same with LINQ normal syntax ? I might get back to this question when very bored, but it is a bad idea to "improve" working code. There's also not much added value in it that I can see.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
suppose i have List1, List2 & List3
now i want to perform left join between List1 & List2 and equi join between List1 & List3 at same place. how to achieve it....if possible please include a sample code.
this kind of join i am looking for
var list1 = new []{
new { CountryID = 12, CountryData = "Has good gras", regionUID = 4567 },
new { CountryID = 12, CountryData = "nice weather", regionUID = 6789 },
new { CountryID = 16, CountryData = "stormy weather", regionUID = 1234 }};
var list2 = new []{
new { CountryID = 12, CountryName = "green hill"},
new { CountryID = 16, CountryName = "stormy mountain"}
};
var list3 = new []{
new {regionUID = 4567, regionName = "above 1000feet"},
new {regionUID = 6789, regionName = "on the ground"},
new {regionUID = 1234, regionName = "on the hill"}
};
var result = from m1 in list1
join m2 in list2 on m1.CountryID equals m2.CountryID
select new { m2.CountryName, m1.CountryData, m1.regionUID } into intermediate
join m3 in list3 on intermediate.regionUID equals m3.regionUID
select new { intermediate.CountryName, intermediate.CountryData, m3.regionName};
but the above code does not suit for my scenario. so please share a sample code where left join between List1 & List2 and equi join between List1 & List3 at same place.
thanks
|
|
|
|
|
They want to change the connection method of a program I write,
this extra request
Clients should connect to the application server, but the connection to the database should be done through the Windows Authentication method over a Windows Service created on the Application server.
what can i do
|
|
|
|
|
As we have no idea what your code currently does, how it works, what its architecture is or even how it's distributed, we aren't going to be able to advise you on how to do this. For instance, does this service already exist or is this something you're going to have to write? What is the purpose of the service? Does it retrieve information?
This space for rent
|
|
|
|
|
SQL Server already allows remote connections over TCP/IP, with authentication, out of the box.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
It's ok,
but i dont understand
Can a service that provides a Sql connection and then return connection , be written
|
|
|
|
|
You don't return the connection. It's only ever used by the data layer.
|
|
|
|
|
You can write a service that executes SQL, but you cannot export your connection, and act as if you are Sql Server.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
And what do you mean by "application server"? What is this and what does it do?
|
|
|
|
|
Like three-tier programming
User-Interface------Dekstop Workstation
Business Logic------Application Server
Data management-----Database Server
|
|
|
|
|
He wants a service where you can "request" SQL connections. Think proxy. Not gonna happen.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
I was wondering what he was talking about. That's the dumbest idea for "serparation of concerns" I've heard in a while.
|
|
|
|
|
Dumb sells.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Maybe you didn't understand the request. A typical "client" knows nothing about "connections" and "application servers".
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Your desktop client may use windows authentication to allow the user access but the connection between your service and database should use a different connection (SQL userid and password) otherwise the users will be able to log into the database directly.
Desktop client -> checks with active directories user/groups for authentication passes info to service
Service (using SQL credentials) checks with database for authorisation of authenticated user.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
Using WSE 3.0 component in my soap based service and cant modify it so it support only ipv4 so when we connect ISP provider IPV6 it throws the error.
How to fix it through the code or service or the network.........expectation is to work with both IPV4 and IPV6
|
|
|
|
|
|
For the moment I can only get the subfolders name of C:\Backup folder to the first column of the listBoxComputer.
Have do I get also the last written date of subfolders to the second column of the listBoxComputer?
private string rootDir = @"C:\Backup";
private void FormView_Load(object sender, EventArgs e) {
List<string> ls = Directory.GetDirectories(rootDir).Select(Path.GetFileName).ToList();
ls.Sort((a, b) => -1 * a.CompareTo(b));
listBoxComputer.Sorted = false;
listBoxComputer.DataSource = ls;
listBoxUser.SelectedIndex =-1;
}
|
|
|
|
|
Member 14055879 wrote: List<string> ls This limits you to a single column of string data. What you need to do is create a model/structure of what you want
Create a class outside this method with the fields you need
class Details{
prop string FileName{get;set;}
prop datetime FileDate{get;set;}
}
Change your list<string> to List
Iterate through the files in the folder
Get the filename and the modified/created attribute
Create a new Details instance with that information
Add the Details just created to the List
Bind the list to your listview.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
The WinForm ListBox has very limited functionality: it does not support multiple columns; the mis-named 'MultiColumn property just does whatever with the text data to avoid vertical scrolling in the control.
Use a ListView [^] instead of a ListBox.
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
Your query makes no sense because you're using directory information to retrieve file info using a method mis-coded as a property.
In any event, you can string multiple fields together (as "strings"), with a possible delimiter (e.g. "|"), and a mono-spaced font, with the left-field (reading left-to-right) padded out (right) to the maximum length ... to get "columns".
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
I have a list which has 25000 data and I am iterating in all data and in each iteration, I am searching data in another data table. my whole routine is taking a long time to finish.
private void UpdateCommentFirst(string strCommentPath, string TickerName)
{
int counter = 0;
bool QcViewAllFileExist = false;
bool QcCommentFileExist = false;
bool AllowUpdate = false;
string savepath = Convert.ToString(ConfigurationManager.AppSettings["OutputPath"]).Trim() + TickerName + "\\" + TickerName + "_QC-ViewwAll.xml";
DataSet QCCommentstmp = new DataSet();
DataSet QCViewAlltmp = new DataSet();
if (File.Exists(strCommentPath))
{
QCCommentstmp.ReadXml(strCommentPath);
QcCommentFileExist = true;
}
if (File.Exists(savepath))
{
QCViewAlltmp.ReadXml(savepath);
QcViewAllFileExist = true;
}
if (QcCommentFileExist && QcViewAllFileExist)
{
if (QCCommentstmp.Tables.Count > 0)
{
if (!QCCommentstmp.Tables[0].Columns.Contains("IgnoreData"))
{
AllowUpdate = true;
}
}
if (AllowUpdate)
{
List<clsCommentPopup> QCCommentlist = QCCommentstmp.Tables[0].AsEnumerable()
.Select(row => new clsCommentPopup
{
bolFollowUP = (row.Field<string>("FollowUP")) == null ? false : Convert.ToBoolean((row.Field<string>("FollowUP"))),
bolThisPeriod = (row.Field<string>("ThisPeriod")) == null ? false : Convert.ToBoolean((row.Field<string>("ThisPeriod"))),
Formula = (row.Field<string>("Formula")) == null ? string.Empty : (row.Field<string>("Formula")),
ModelValue = (row.Field<string>("ModelValue")) == null ? string.Empty : (row.Field<string>("ModelValue")),
ExternalComment = (row.Field<string>("ExternalComment")) == null ? string.Empty : (row.Field<string>("ExternalComment")),
InternalComment = (row.Field<string>("InternalComment")) == null ? string.Empty : (row.Field<string>("InternalComment")),
strEndPeriod = (row.Field<string>("EndPeriod")) == null ? string.Empty : (row.Field<string>("EndPeriod")),
strStartPeriod = (row.Field<string>("StartPeriod")) == null ? string.Empty : (row.Field<string>("StartPeriod")),
PeriodType = (row.Field<string>("PeriodType")) == null ? string.Empty : (row.Field<string>("PeriodType")),
SectionFor = (row.Field<string>("Section")) == null ? string.Empty : (row.Field<string>("Section")),
LiFor = (row.Field<string>("LineItem")) == null ? string.Empty : (row.Field<string>("LineItem")),
QcPeriodFor = (row.Field<string>("QcPeriod")) == null ? string.Empty : (row.Field<string>("QcPeriod")),
BrokerFor = (row.Field<string>("BrokerFor")) == null ? string.Empty : (row.Field<string>("BrokerFor")),
PeriodCollection = (row.Field<string>("PeriodCollection")) == null ? string.Empty : (row.Field<string>("PeriodCollection")),
boolIgnoreValue = (row.Field<string>("IgnoreValue")) == null ? false : Convert.ToBoolean((row.Field<string>("IgnoreValue"))),
IgnoreData = (!QCCommentstmp.Tables[0].Columns.Contains("IgnoreData") ? string.Empty : (row.Field<string>("IgnoreData") == null ? string.Empty : row.Field<string>("IgnoreData")))
}).ToList();
if (QCCommentlist != null)
{
foreach (var comment in QCCommentlist)
{
string section = comment.SectionFor;
string li = comment.LiFor;
string broker = comment.BrokerFor;
string period = comment.PeriodCollection;
string strQCPeriodValue = "";
if (comment.boolIgnoreValue && period.Trim() != "")
{
var QcViewColumnName = QCViewAlltmp.Tables[0].Columns.Cast<DataColumn>().AsParallel()
.Where(x => x.ColumnName.Contains(period))
.Select(x => new { x.ColumnName }).FirstOrDefault();
if (QcViewColumnName != null)
{
period = QcViewColumnName.ColumnName;
if (period.Trim() != "")
{
var datarow = QCViewAlltmp.Tables[0].AsEnumerable().AsParallel()
.Where(row => row.Field<string>("GroupKey").Split('~')[0].ToUpper() == section.ToUpper()
&& row.Field<string>("GroupKey").Split('~')[1].ToUpper() == li.ToUpper()
&& row.Field<string>("Section ").ToUpper() == broker.ToUpper());
if (datarow != null && datarow.Count() > 0)
{
strQCPeriodValue = (datarow.FirstOrDefault()[period] != null ? datarow.FirstOrDefault()[period].ToString() : string.Empty);
if (strQCPeriodValue.Trim() != string.Empty)
{
comment.IgnoreData = strQCPeriodValue;
counter++;
}
}
}
}
}
}
}
SerializeQcComment(QCCommentlist);
toolTip1.Hide(this);
}
}
}
Loading data from XML file into a dataset.
If the ignoredata field is there in QCCommentstmp dataset table
QCCommentstmp.Tables[0].Columns.Contains("IgnoreData") then deserialize QCCommentstmp table data to list List<clscommentpopup> QCCommentlist.
Iterate in QCCommentlist's data using a for loop and finding data in QCViewAlltmp.Tables[0] data table for each iteration.
When QCCommentlist has 25000 data then I am iterating in all 25000 data and finding data in another data table. If data is found then I am updating data in the list. This process is getting very slow and the code is taking a long time to finish all the iteration and searching data in the data table.
Please review my code and tell me how to restructure my code, as a result, there will be the improvement in code execution speed.
If my approach is wrong then guide me with the right approach and also give me the relevant code which I can use in my above code, as a result, my routine will take minimum time to finish if I iterate in more than 25000 data. I'm looking for suggestions and better code to achieve the same task. thanks
|
|
|
|
|
Hi,
I'm no expert in LINQ, however I would avoid using it for searching as it is based on IEnumerable, so I expect a search to be basically sequential, and performance to degrade quadratically.
I would recommend first building a Dictionary<keyType, myType> with the search key as key; that would speed up your search considerably. Be careful though, all key values must be different when building the dictionary!
modified 7-Apr-19 22:15pm.
|
|
|
|