« first day (2355 days earlier)      last day (2588 days later) » 

5:02 PM
let me know when you run into issues
 
5:19 PM
Good evening!
So for some reaosn I have never really understood how .Distinct() works with LinQ.
I've currently got a database with posts for a blog, where one of the fields is "Category", and on the site, I got a dropdown list with all the categories.
However, doing this in my DataContext, still displays multiple items of the same category name in the dropdown :
gist: a4744d24da0e55bd3110ffaef39dda39, 2017-03-28 17:21:04Z
public IQueryable<Post> GetPost()
        {
            var query = (from p in Post
                         select new Post
                         {
                             Id = p.Id,
                             Header = p.Header,
                             Text = p.Text,
                             DateCreated = p.DateCreated,
                             Thumbnail = p.Thumbnail,
                             Category = p.Category,
                         }).Distinct();

            return query;
        }
 
user7480455
hi
 
@Xariez You'd be looking for DistinctBy, which I don't recall being built-in
 
user7480455
with distinct you line items need to be different
 
But in that case, is there any way I can, using built in functions, prevent duplicates?
 
user7480455
if you items have the same values they will not be filtered
 
user7480455
5:23 PM
ohh hmmm
 
You could use GroupBy(x => x.Category).Select(x => x.First()) I think
 
user7480455
group by would work
 
Well, that would just select one Category, wouldnt it?
 
No
It would select one item from each category
 
user7480455
what happens when you do this query in sql
 
5:24 PM
Ah
Well thats not too possible either I believe.
 
user7480455
you could do a nested query that would first get a single category
 
To better illustrate it, thats what the database look like
 
user7480455
then use that id to get the line items
 
user7480455
that's blocked for me :(
 
Better?
 
user7480455
5:26 PM
wow how did you do that?
 
user7480455
yes I can see it
 
user7480455
that's neat
 
The "upload" button to the right.
Instead of just uploading it to imgur.
 
user7480455
Idon't have that button but cool
 
user7480455
lets take a look at that data
 
5:28 PM
So as you can see, i got 4 posts. They can have whatever category they want, but in the dropdown list o the site, I want the categories to display "TestCategory - Tech", right now its displaying "TestCategory - Tech - TestCategory - TestCategory"
 
user7480455
yeah
 
user7480455
remove the ID that will always make it distinct
 
Thats currently being being "looped" out using a foreach,
@foreach (var category in ViewData["GetCategories"] as IQueryable<CMS.Models.Post>)
Alright, so i remove the ID. Then what?
I doubt linq is smart enoguh to prevent duplicates on its own
 
user7480455
currently with ID a record will always be distinct because 1. 2. 3. are different and distinct
 
user7480455
just looking how you can drill it down
 
user7480455
5:30 PM
same with dates... a different date make the record different
 
Yeah, that's true.
 
user7480455
can you type out an example of what you would like to see
 
But for some reason I always thought .Distinct() REMVOES duplicates?
 
user7480455
line item wise
 
user7480455
it can
 
5:31 PM
Currently getting:
* TestCategory *
* Tech *
* TestCategory *
* TestCategory *
What I'm looking for is:
* TestCategory *
* Tech *
 
user7480455
ok
 
user7480455
group by Category
 
user7480455
and don't select any of the other fields
 
user7480455
that will get you the basic output you need
 
user7480455
but do you also need any of the other fields?
 
5:34 PM
I do.
But, I can make a seperate action for that
 
user7480455
ok
 
gist: a4744d24da0e55bd3110ffaef39dda39, 2017-03-28 17:21:04Z
public IQueryable<Post> GetPost()
        {
            var query = (from p in Post
                         select new Post
                         {
                             Id = p.Id,
                             Header = p.Header,
                             Text = p.Text,
                             DateCreated = p.DateCreated,
                             Thumbnail = p.Thumbnail,
                             Category = p.Category,
                         }).Distinct();

            return query;
        }
Right now I got that, i could remove anything category related from that one, and make a seperate one just getting the Categories
 
user7480455
yes you could
 
user7480455
I am trying to think of a way where you could do this
 
user7480455
in one shot
 
5:37 PM
@Xariez Are you looking for a list of categories, or a list of items in distinct categories?
 
I guess the first named would be both easier and "better" to do in this case.
Since its simply a dropdown list where you browse categories, and then when the page loads, i could have another query sending in the posts based on the URL
 
user7480455
I was just in sql as I have a table where I have something like you have
 
user7480455
and if do a select distinct category
 
user7480455
I get just the two values
 
user7480455
but of course that only gives me that field..
 
user7480455
5:40 PM
once you start expanding fields the records become unique
 
One needs to remember the categories can change dynamically though
 
user7480455
so this is a tuffy
 
user7480455
There are some really sharp people that come into the forum so I am sure they may have a better solution
 
It seems pretty simple to me, I must not be understanding
 
It seems simple to me as well, lol
But basically, imagine you got a list. In this list you got Categories, and when you click on a Category, it sends the category name to the URL, and filters the posts shown on the site based on that
 
5:45 PM
So what's the issue?
 
user7480455
like a drill down
 
The category names are showing up duplicated
 
user7480455
yeah just take the reast of the fields out
 
user7480455
and do your select distinct
 
@Xariez Didn't I give you a way to solve that?
 
user7480455
5:46 PM
and then use the cat id to filter the other drop down
 
user7480455
dont think that should be a prob
 
user7480455
in the other list you would then find by the cat id
 
Will try that, 1s! @007
You did, but with a non-built in function @KendallFrey
 
user7480455
the way you had your select had too many fields. this made the line items appear unique
 
@Xariez No, I told you how to implement the same thing using only Standard LINQ
 
5:49 PM
Distinct can take an IEqualityComparer.
 
user7480455
ah here come the gurus lol
 
That would allow you to write and equals method for the item
 
Ah, must have understood that incorrectly then! @KendallFrey
 
If all you want is a list of distinct categories, that's Select(x => x.Category).Distinct()
 
Thats what I came into this chat with. And it didn't do shit. @KendallFrey
We wanted to remove the ID field as well, correct? @007
 
user7480455
5:51 PM
I think you had all the fields right?
 
user7480455
yes sir
 
ii just realised..
 
user7480455
except category ID if yo uahve it
 
user7480455
if not you will have to find by the text value
 
The ID might be needed afterall, because thats what i send in the URL whenever a user edits a post
 
user7480455
5:52 PM
yeah
 
It doesn't necessarely have to be set as a primary key though i guess?
nvm
 
user7480455
cat id with the cat text will be dups and the distinct will deal with it
 
user7480455
I dont think so
 
Alright, so regarding LinQ and database queries, this is what i got now. gist.github.com/JohannesSundqvist/…
We expecting this to work? Or do I still needed to add a groupby?
 
What are you trying to do? If you are trying to return the entire record but have it distinct by a certain field or get a list of distinct items?
 
5:54 PM
@Xariez That's not what you originally had
 
user7480455
that should be gold
 
Nope, it's not. @KendallFrey
 
if its the first, look up distinctby or define an IEqualityComparer and pass it into Distinct
 
@Xariez Do you want a list of posts, or a list of categories? This is the third time you've been asked this question.
 
It's the second time I've been asked that question.
And it's the second time I'm answering it.
At this point, a list of categories.
 
5:56 PM
Then it's Select(x => x.Category).Distinct()
 
yeah
You don't select a post, you select the category
 
Hmm, alright, that does sound easy. Let me check
 
Any regex gurus online?
 
Is it possible to get the Application "Executable" Location of an .NET Core Application? The folder where the executable is located.
 
If you need the whole post, you need to do more work
 
5:56 PM
@SamyS.Rathore I try
 
@"from INEXCHG02.navbackoffice.com (172.16.0.211) by INEXCHG02.navbackoffice.com(172.16.0.211) with Microsoft SMTP Server (TLS)id 15.0.1178.4 via Mailbox Transport; Tue, 28 Mar 2017 19:15:28 + 0530
                            from INEXCHG01.navbackoffice.com (172.16.0.209) by INEXCHG02.navbackoffice.com(172.16.0.211) with Microsoft SMTP Server (TLS)id 15.0.1178.4; Tue, 28 Mar 2017 19:15:25 + 0530
                            from mailgtw.navbackoffice.com (172.16.0.210) by INEXCHG01.navbackoffice.com(172.16.0.209) with Microsoft SMTP Server (TLS)id 15.0.1178.4 via Frontend Transport; Tue, 28
 
user7480455
wow
 
The whole post I already got! :) @TylerStahlhuth
 
user7480455
what is that?
 
I have a string like this
I need to extract the domain names from it
for e.g. INEXCHG02.navbackoffice.com
or just navbackoffice.com
 
user7480455
5:57 PM
you guys do some hightech stuff! lol
 
I mean if you want the distinct posts by a category. @Xariez
 
Ah
I see
Yeah, for that I'm using _context.GetPost().Where(x => x.Category == url)
 
No one? :)
 
And URL is string url = Url.ActionContext.RouteData.Values["id"].ToString();
 
Right, but that isn't Distinct by category.
you could have multiples of the same category
I think you have a naming problem
 
5:59 PM
@KendallFrey Any pointers for me?
 
@SamyS.Rathore You asked for a regex guru, but you really needed google
 
Object reference not set to instance of an object,
@foreach (var category in ViewData["GetCategories"] as IQueryable<CMS.Models.Post>)
Surprisingly, that's what im getting when trying to use ViewData["GetCategories"] = _context.GetPost().Select(x => x.Category).Distinct();
 
You are using Entity Framework?
 
I am
 
clearly ViewData["GetCategories"] is not of type IQueryable<CMS.Models.Post>
 
6:01 PM
Is GetPost a mapped stored procedure?
 
@KendallFrey I did google it, guess I failed -_-'
 
@milleniumbug Or it's null
 
GetPost is "IQueryable<Post> GetPost;" in an interface, which in its turn is the database query
 
I know this is a C# but I need a sql question. Can anyone help?
 
6:02 PM
How can I combine this two item in one single command?
BEGIN TRAN
use SupplementalFood
GO
update Voucher
set Confirmed = '1'
where VoucherID between 5705 and 5707;
--rollback commit

BEGIN TRAN
USE SupplementalFood
GO
update Voucher
set Confirmed = '1'
where VoucherID BETWEEN 5691 and 5696;
--rollback commit
 
Not sure if anyone can help, but don't ask to ask either way. Shoot :)
Alright, the solution that @007 proposed works and that's what i'll roll with. Thanks!
 
update Voucher
set Confirmed = '1'
where (VoucherID > 5691 and VoucherID < 5696) or
(VoucherID > 5705 and VoucherID < 5707)
 
where (VoucherID between 5705 and 5707) or (VoucherID between 5691 and 5696)?
Oh... let me try yours @TylerStahlhuth
 
Looks like between works also, i just haven't used it before
also looks like it's an >= and <= not just < and >;
 
user7480455
cool
 
6:13 PM
hello everyone
 
@TylerStahlhuth Ok manager wants me to list every single one of them and us the IN command. I have to list 5705, 5704, 5705, 5691, 5692,.... 5696
 
user7480455
hiX
 
I always come here with some silly issues and Kendall makes it looks like child's play and I end up feeling silly
thanks though :)
 
@Sandy2016 Umm... that seems excessive... but it would be where VoucherID in (5705, 5706, 5707, 5691, 5692, 5693, 5694, 5695, 5696)
 
That's what I'm thinking.
I will try that. @TylerStahlhuth
Thanks! @TylerStahlhuth
 
6:21 PM
That didn't work as expected...
lol
 
Hahaha!!!! right!
I might type a wrong number doing that. I told him that and his like do it this way. End of story. lol
 
You can use an IN command with a large amount of values in it before the performance becomes a problem. I have done some testing before, and anything under 10,000 values is still very fast.
 
user7480455
hi all... so how do you send more than one parameter to a controller function as I am typing to to this by typing
 
user7480455
I found this mysite/Controller/Action?date=21-9-2009 10:20
 
you can't have spaces in urls...
 
user7480455
6:24 PM
but I need to send to date and then two times as they are time spans
 
Anyway, each new parameter is supposed to be separated by an &, and that is it for a get request like you list.
 
user7480455
can you show an example
 
user7480455
I have date 1 date 2 time 1 time 2
 
user7480455
also when I go to the url will it navigate to a different page? This is what I have trouble following as I don't want to goto a new page.. I just want to run a function
 
You need to encode your dates, first off. Anyway, you mean like this as an example?
Action?Date1=03%2F19%2F2017&Date2=03%2F23%2F2017&StringArray1%5B0%5D=stuff&StringArray2%5B0%5D=paces
 
user7480455
6:28 PM
as ok
 
user7480455
ah I mean
 
you have to use ajax if you want to avoid page relocation
 
user7480455
I wantto avoid ajax
 
user7480455
this is troubling...
 
Why do you want to avoid ajax? It is the peanut butter to the internet's jelly.
Unless you are using a socket.
 
user7480455
6:30 PM
I dont understand it mainly Steve gave me a nice tutorial but I am having trouble unstanding how to make use of it
 
.... ... ........................
 
user7480455
i dont need the complexity I just need a function to run
 
user7480455
lo
 
user7480455
l
 
user7480455
what was the array part of your example?
 
user7480455
6:31 PM
and what is paces
 
paces was a string
StringArray2[0] = paces
StringArray1[0] = stuff
Date1 = 3/19/2017
Date2 = 3/23/2017
 
user7480455
if I don't have a paces in my parameter I dont need that right
 
user7480455
oh ok
 
You asked for an example querystring, and I gave you one
 
user7480455
And I thank you
 
user7480455
6:33 PM
just trying to understand how it is formed
 
Do you know how to make a form and submit it?
 
user7480455
thats the problem... I don't want to submit a form
 
user7480455
I just wantto update a drop list...
 
I know that.
Now answer my question :D
 
user7480455
I think I am being guided into the wrong direction because my question is not clear
 
user7480455
6:34 PM
not sure how that question is relevant
 
user7480455
if im honest
 
Okay, so you can make a form and submit it to an actionresult like normal then? And have it bind and everything?
 
user7480455
yeah I'm not sure what you are asking
 
user7480455
but ok
 
user7480455
I used the wizard to make my forms
 
user7480455
6:36 PM
and to make my views
 
user7480455
this is a database first app so I did not had code my forms
 
If you leave that actionresult untouched, and in the view you use var data = $("#yourForm").serialize() and then send that with $.ajax() it will hit your actionresult and bind just as if you had submitted the form
 
user7480455
so it's doing alot of the majic
 
user7480455
magic
 
But it wont reload the page.
 
user7480455
6:37 PM
hmmm
 
user7480455
let me make some notes
 
user7480455
hmm yeah I may have to go to the PM and get reassigned...
 
user7480455
lol
 
user7480455
6:38 PM
I am over my head
 
can you use dotnetfiddle?
 
user7480455
I don't know what that is...
 
user7480455
but I will look it up
 
user7480455
is this an online compiler?
 
yes, it can compile and serve mvc demos
 
user7480455
6:41 PM
where you have Action?Date1 in your example should that my the name of my action or should it be just action
 
user7480455
wow I have never heard of that.. this looks cool
 
God damn
is the response from Caprica six from the !!kieran command always going to get starred when it happens?
Why must you all torment me this way
 
!!kieran
 
and with that
 
Feb 27 at 16:02, by Kieran
Thank you for confirming im an idiot c:
 
6:42 PM
God dammit mike
I'm going home
and by going home
I mean going down to the front room
laters o/
 
You brought this on yourself.
 
user7480455
by
 
user7480455
bye
 
Well that may be, doesn't mean i wont complain about it @mikeTheLiar
 
user7480455
I mean
 
user7480455
6:45 PM
also travis j if I want to send time will t be formatted like the date?
 
user7480455
if it's just time with out a date prefix?
 
No, you need to send the date and the time separately.
 
user7480455
my function in the controller function(date1, date2,Time1, Time2) I don't have it equal to a string like in your case you have it all equal to pace
 
Unless you send a epoch millisecond value
 
user7480455
no I have it just a 14:00
 
user7480455
6:48 PM
as
 
!!kieran
 
Feb 27 at 16:02, by Kieran
Thank you for confirming im an idiot c:
 
user7480455
but I am not sure how to fit that into your format
 
@007 datetimes have culture
fyi
 
user7480455
so far I have
 
user7480455
6:49 PM
Action?StartDate=03%2F19%2F2017&EndDate=03%2F23%2F2017&StartTime1%5B0%5D=stuff&E‌​ndTime2%5B0%5D=paces
 
oh jeez rick
 
user7480455
just not sure what's next
 
user7480455
hi fail
 
user7480455
yeah I know.. but calling a function in a controller seems to be a real horror show!
 
user7480455
you don't see this type of break down on the puralsite lol
 
user7480455
wow thanks studying now/
 
(updated) the prev one had some fluff left in it
that should be pretty barebones
 
user7480455
so I will ask you like I asked steve.. the httppost will that need the page to be submitted/
 
user7480455
?
 
get = get data, post = create data, put = update data, delete = delete data
 
6:56 PM
When you click test, it submits the form via ajax. The page does not reload, and the server response is alerted.
 
if you're doing ajax, nothing has to be 'submitted' w/ a page refresh, it's all done behind the scenes
 
If you are using chrome, you can see the request and response, by opening the network tab
 
same w/ firefox
 
user7480455
yeah I have watched the network page... these are just refreshes
 
user7480455
not submission to the database
 
user7480455
6:57 PM
if you have a database
 
The server communicates with the database, in your actionresult you can have the method use the database
 
^
 
user7480455
ok... I must have misread how it all work
 

« first day (2355 days earlier)      last day (2588 days later) »