Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

22 Eargesplitten posted:

What's the point of a getter and setter if the syntax for calling them is the same as getting the variable if it were a public variable? I thought the point of getters and setters was to make sure that nothing outside that class could access the variable without going through a specific method call.

Also, why can't I set a variable to be private and then make the getters and setters public? Coming from Java, this whole thing seems weird.

The idea is that you want fields to represent the internal state of your class, and allow access to them through methods responsible for accessing/mutating them. In Java, this is clumsily accomplished through having a bunch of boilerplate methods for getThing/setThing. If you want something to be invisible from outside the class, don't provide get/set methods. If you want something to be readonly, don't provide a set method.

Properties are just cutting the boilerplate out. You get a backing field and get/set methods without having to write a ton of extra crap. If you need to put some validation logic or something of the like in later, nothing from outside the class needs to change. Fields and properties are not interchangeable -- changing a field to a property changes the IL generated and represents a breaking change to the application that requires all dependent assemblies to be recompiled.

Your last question doesn't make sense, partially because of ambiguity: A "field" is a class-level variable (public int Foo = 0;. A "property" is an auto-implemented field with appropriate get/set methods (public int Foo { get; set; } = 0). If you're talking about something like this:

code:
private int Foo { public get; public set; }
If you're making a property entirely private, you might as well just use a field. A private set method would make it read-only, which makes sense -- you might want something to be able to read the state of the variable but not mutate it.

Adbot
ADBOT LOVES YOU

SirViver
Oct 22, 2008

22 Eargesplitten posted:

What's the point of a getter and setter if the syntax for calling them is the same as getting the variable if it were a public variable? I thought the point of getters and setters was to make sure that nothing outside that class could access the variable without going through a specific method call.
Yes, that is their point. The syntax being like a variable access (that btw during compile gets rewritten to a classic get() or set() method call) just makes things nicer to look at and condenses separate get/set methods into a single property. It still fulfills the same purpose as manually written getter and setter methods.

Of course, if you just use auto-implemented properties like
C# code:
public int MyProperty { get; set; }
then that by itself doesn't yet do anything different than just exposing a public variable. However, what it does do is future proof your class for the case where you might add some sort of validation later, in which case you would replace the auto-implemented property with a manually implemented one like so
C# code:
private int _myProperty;
public int MyProperty 
{ 
    get { return _myProperty; } 
    set 
    {
        if (value < 0)
            throw new ArgumentOutOfRangeException("value", value, nameof(MyProperty) + " must not be lower than zero.");
        _myProperty = value;
    }
}
This can be done completely transparently to the caller; your class interface has not changed and no calls need to be rewritten.

22 Eargesplitten posted:

Also, why can't I set a variable to be private and then make the getters and setters public? Coming from Java, this whole thing seems weird.
I'm not quite sure what you mean by that? Private backing variable with public getter/setter property is pretty much the standard use case - see above. What you can also do is make private, protected, or internal properties, or make getter and/or setter have a more restrictive accessibilty.
C# code:
// Visible to everyone, but the value can only be set by the class
public int MyProperty { get; private set; }
// Visible to classes within the same assembly, but the value can only be set by the class or by derived classes
internal int MyProperty { get; protected set; }
// Visible to this class and derived classes, but only this class can read the value - derived classes may only set the value
// (This is weird af)
protected int MyProperty { private get; set; }

EssOEss
Oct 23, 2006
128-bit approved
Installing the System.Net.Http package breaks .NET Framework applications. This library is a dependency of the NETStandard.Library package. This means you cannot reference .NET Standard libraries in .NET Framework apps without fatally breaking some basic HTTP functionality.

"[The fix] will be part of the .NET Core 1.1 release. I believe the timing is within a few months." was the developer response.

:psyduck:

Just when I thought maybe this new .NET was getting perhaps half mature.

dougdrums
Feb 25, 2005
CLIENT REQUESTED ELECTRONIC FUNDING RECEIPT (FUNDS NOW)

Ithaqua posted:

The idea is that you want fields to represent the internal state of your class, and allow access to them through methods responsible for accessing/mutating them. In Java, this is clumsily accomplished through having a bunch of boilerplate methods for getThing/setThing. If you want something to be invisible from outside the class, don't provide get/set methods. If you want something to be readonly, don't provide a set method.

Also, fields can be used in interface definitions, so it is common to find that an auto implemented field is simply satisfying the interface definition.

dougdrums fucked around with this message at 08:51 on Sep 19, 2016

Inverness
Feb 4, 2009

Fully configurable personal assistant.

EssOEss posted:

Installing the System.Net.Http package breaks .NET Framework applications. This library is a dependency of the NETStandard.Library package. This means you cannot reference .NET Standard libraries in .NET Framework apps without fatally breaking some basic HTTP functionality.

"[The fix] will be part of the .NET Core 1.1 release. I believe the timing is within a few months." was the developer response.

:psyduck:

Just when I thought maybe this new .NET was getting perhaps half mature.
How does this not require an immediate bug fix release? :wtc:

biznatchio
Mar 31, 2001


Buglord
I thought the whole point of putting things as separate packages in Nuget was so they could fix issues without having to wait for a monolithic release?

22 Eargesplitten
Oct 10, 2010



SirViver posted:

Yes, that is their point. The syntax being like a variable access (that btw during compile gets rewritten to a classic get() or set() method call) just makes things nicer to look at and condenses separate get/set methods into a single property. It still fulfills the same purpose as manually written getter and setter methods.

Of course, if you just use auto-implemented properties like
C# code:
public int MyProperty { get; set; }
then that by itself doesn't yet do anything different than just exposing a public variable. However, what it does do is future proof your class for the case where you might add some sort of validation later, in which case you would replace the auto-implemented property with a manually implemented one like so
C# code:
private int _myProperty;
public int MyProperty 
{ 
    get { return _myProperty; } 
    set 
    {
        if (value < 0)
            throw new ArgumentOutOfRangeException("value", value, nameof(MyProperty) + " must not be lower than zero.");
        _myProperty = value;
    }
}
This can be done completely transparently to the caller; your class interface has not changed and no calls need to be rewritten.

I'm not quite sure what you mean by that? Private backing variable with public getter/setter property is pretty much the standard use case - see above. What you can also do is make private, protected, or internal properties, or make getter and/or setter have a more restrictive accessibilty.
C# code:
// Visible to everyone, but the value can only be set by the class
public int MyProperty { get; private set; }
// Visible to classes within the same assembly, but the value can only be set by the class or by derived classes
internal int MyProperty { get; protected set; }
// Visible to this class and derived classes, but only this class can read the value - derived classes may only set the value
// (This is weird af)
protected int MyProperty { private get; set; }

Okay, that makes more sense now. I think I'll need to use it more for it to really sink in, but it's a start. The second example is the way I generally did it in Java.

darthbob88
Oct 13, 2011

YOSPOS
So what's the right way to handle passing a MemoryStream between projects, and specifically across an HTTP request? This is for work so I can't get too specific, but I have a project for exporting/importing stuff to and from Excel, a project for handling the API for this whole solution, and a UI project which makes HTTP calls to the API, and I want to be able to serialize a (possibly quite large) Excel file in the Excel project, pass that to the API, and pass that to the UI project where the final user can download it as a file on their machine. I've tried a naive solution, just doing that like I said, but I've run into problems with (de)serializing the MemoryStream, so obviously there's some additional wrinkle I've missed. Probably just the fact that I need to convert the stream to an actual object rather than a stream before sending it across the wires?

kitten emergency
Jan 13, 2008

get meow this wack-ass crystal prison
my favorite new thing is discovering a dude who just uploads Microsoft libs to nuget that they don't put there themselves, but with subtly different versions so if you grab something that should match, whoops, you actually needed this other one!

does nuget.org not have protected namespaces for vendors?

ljw1004
Jan 18, 2005

rum

uncurable mlady posted:

my favorite new thing is discovering a dude who just uploads Microsoft libs to nuget that they don't put there themselves, but with subtly different versions so if you grab something that should match, whoops, you actually needed this other one!

Could you point me to one please?

kitten emergency
Jan 13, 2008

get meow this wack-ass crystal prison

ljw1004 posted:

Could you point me to one please?

https://www.nuget.org/profiles/bmarshall

kitten emergency
Jan 13, 2008

get meow this wack-ass crystal prison
I didn't exhaustively go through them but I'd expect anything in the MS namespace to be listed by MS. We explicitly got tripped up by a different package that wasn't an MS one on there and idk if it was a fuckup on our end or what but I don't think dude has ownership either way

AWWNAW
Dec 30, 2008

darthbob88 posted:

So what's the right way to handle passing a MemoryStream between projects, and specifically across an HTTP request? This is for work so I can't get too specific, but I have a project for exporting/importing stuff to and from Excel, a project for handling the API for this whole solution, and a UI project which makes HTTP calls to the API, and I want to be able to serialize a (possibly quite large) Excel file in the Excel project, pass that to the API, and pass that to the UI project where the final user can download it as a file on their machine. I've tried a naive solution, just doing that like I said, but I've run into problems with (de)serializing the MemoryStream, so obviously there's some additional wrinkle I've missed. Probably just the fact that I need to convert the stream to an actual object rather than a stream before sending it across the wires?

HTTP responses are already a stream. Are you trying to just
code:
return myMemStream;
from within a ASP.NET method? If so I don't think it'll work like that. You can try setting the response's content type to application/octet-stream or <I can't be bothered to look it up> and then doing something like myMemStream.CopyTo(Response.OutputStream). I'm sure there are 1,000 StackOverflow questions on this very topic.

e: Try this one for example: http://stackoverflow.com/a/26041298

AWWNAW fucked around with this message at 02:08 on Sep 20, 2016

Inverness
Feb 4, 2009

Fully configurable personal assistant.

darthbob88 posted:

So what's the right way to handle passing a MemoryStream between projects, and specifically across an HTTP request? This is for work so I can't get too specific, but I have a project for exporting/importing stuff to and from Excel, a project for handling the API for this whole solution, and a UI project which makes HTTP calls to the API, and I want to be able to serialize a (possibly quite large) Excel file in the Excel project, pass that to the API, and pass that to the UI project where the final user can download it as a file on their machine. I've tried a naive solution, just doing that like I said, but I've run into problems with (de)serializing the MemoryStream, so obviously there's some additional wrinkle I've missed. Probably just the fact that I need to convert the stream to an actual object rather than a stream before sending it across the wires?
Not sure if this is helpful to you but there is a special Socket.SendFile() method that calls the Win32 TransmitFile() API. This is recommended if you're sending large files over the network.

Not sure if the HTTP classes have methods that wrap this.

Horn
Jun 18, 2004

Penetration is the key to success
College Slice

I'm dumbfounded that this is allowed by nuget. Hopefully this rear end gets nuked with extreme prejudice.

darthbob88
Oct 13, 2011

YOSPOS

AWWNAW posted:

HTTP responses are already a stream. Are you trying to just
code:
return myMemStream;
from within a ASP.NET method? If so I don't think it'll work like that. You can try setting the response's content type to application/octet-stream or <I can't be bothered to look it up> and then doing something like myMemStream.CopyTo(Response.OutputStream). I'm sure there are 1,000 StackOverflow questions on this very topic.

e: Try this one for example: http://stackoverflow.com/a/26041298
No, the API is returning
code:
this.Ok(myMemStream);
, which should have worked fine. I suspect the real/bigger problem is the consumer, which reads that stream as a string and then tries to deserialize that string to JSON; works fine with objects, less well with streams. Will try changing things to fit that StackOverflow answer.

ljw1004
Jan 18, 2005

rum

AWWNAW posted:

HTTP responses are already a stream. Are you trying to just
code:
return myMemStream;
from within a ASP.NET method? If so I don't think it'll work like that. You can try setting the response's content type to application/octet-stream or <I can't be bothered to look it up> and then doing something like myMemStream.CopyTo(Response.OutputStream). I'm sure there are 1,000 StackOverflow questions on this very topic. e: Try this one for example: http://stackoverflow.com/a/26041298

I'm not an expert in this area, but I did search around when I looked into this a year ago, and I came to the opposite conclusion. I found places which told me you CAN return a stream, and than ASP.NET will itself take over responsibility for copying the stream and disposing your stream handle once it's done. Of course I can't find them right now. All I left in my code was a comment that it is allowed.

code:
    <HttpGet, Route("onedrive/{driveId}/{rootId}/{vanity}")>
    Public Async Function Proxy(driveId As String, rootId As String, vanity As String, authkey As String, fn As String, folder As String, Optional subfolder As String = Nothing) As Task(Of HttpResponseMessage)
        Dim client As New HttpClient
        Dim url = OnedriveProxyLinker.GenerateOnedriveLink(driveId, rootId, authkey, folder, subfolder, fn)
        If fn.EndsWith(".xml") Then
            Dim resp As New HttpResponseMessage(Net.HttpStatusCode.OK)
            Dim content = Await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead)
            resp.Content = New StreamContent(Await content.Content.ReadAsStreamAsync)
            resp.Content.Headers.ContentType = New MediaTypeHeaderValue("application/rss+xml")
            Return resp
            ' This transfers responsibility over to ASP.NET to continue reading+writing the stream,
            ' and then close it at the end
        Else
            Dim resp As New HttpResponseMessage(Net.HttpStatusCode.Found)
            resp.Headers.Location = New Uri(url)
            Return resp
        End If
    End Function
Here's another site which suggests, as I've done, that you can just hand over the stream + responsibility for it to ASP.NET:
http://blog.guvweb.co.uk/2014/07/02/streaming-web-api/


Caveat: I might be misunderstanding something here! And I don't know if the same is true of ASP.NET Core.

Gul Banana
Nov 28, 2003

Horn posted:

I'm dumbfounded that this is allowed by nuget. Hopefully this rear end gets nuked with extreme prejudice.

these packages definitely seem misleading. but I hope they don't take down whoever it is that uploads stuff like the Blend SDK, which would otherwise be an irritating install on everyone's machines just to get System.Windows.Interactivity...

ljw1004
Jan 18, 2005

rum

I asked the CLR/WinRT interop guy to reply to that thread. Is an interesting read.

raminasi
Jan 25, 2005

a last drink with no ice

ljw1004 posted:

I asked the CLR/WinRT interop guy to reply to that thread. Is an interesting read.

I generally agree with that guy's sentiment, but that "style" of bug reporting is so loving grating.

dougdrums
Feb 25, 2005
CLIENT REQUESTED ELECTRONIC FUNDING RECEIPT (FUNDS NOW)
It's leakin' memory like a hell!

Wait is this dude complaining that the clr isn't freeing native memory for him?

Yeah it made more sense after I read beyond his op. Strange way to describe a problem though... vvvvv

dougdrums fucked around with this message at 13:52 on Sep 21, 2016

Mr Shiny Pants
Nov 12, 2012

dougdrums posted:

It's leakin' memory like a hell!

Wait is this dude complaining that the clr isn't freeing native memory for him?

No, he is saying that the stuff is leaking memory when it should not and nowhere is it made apparent how to stop it or why it does it.

Kekekela
Oct 28, 2004

dougdrums posted:

It's leakin' memory like a hell!


New thread title, please

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

22 Eargesplitten posted:

What's the point of a getter and setter if the syntax for calling them is the same as getting the variable if it were a public variable? I thought the point of getters and setters was to make sure that nothing outside that class could access the variable without going through a specific method call.

Also, why can't I set a variable to be private and then make the getters and setters public? Coming from Java, this whole thing seems weird.

It feels like no one addressed your *specific* concern here so I'll throw in my two cents:

Properties in C# are syntactic sugar over the exact same get/set pattern you use in Java. So the following code is equivalent:

C# code:
class Butt
{
    private int poop;

    public int Poop
    {
        get { return poop; }
        set { poop = value; }
    }
}
Java code:
class Butt {
    private int poop;

    public int getPoop() {
        return poop;
    }

    public void setPoop(int value) {
        poop = value;
    }
}
There's your "private field + public getters and setters". They're exactly the same pattern, it's just more succinct in C#.

When you use them the C# code is exactly equivalent to the Java code (in fact the intermediate bytecode language is virtually identical to the Java code):

C# code:
var b = new Butt();
b.Poop = 4;              // exactly the same as b.setPoop(4);
int p = b.Poop;        // exactly the same as int p = b.getPoop();
C# uh.... 4 I think? introduced additional syntax for auto properties. It is often the case that a getter and setter are trivial (like in the examples above) so the C# compiler says hey I can generate this code for you. So with auto properties the above example becomes:

C# code:
class Butt
{
    public int Poop { get; set; }
}
Again, to stress this, this is *exactly the same* as the code in our first C# example and exactly equivalent to the get/set pattern of Java. You're just relying on the compiler to generate the boilerplate for you.

Finally in C# 6 they introduced an additional bit of syntax. Sometimes you want to initialize your property to something other than the default. Autoproperties won't let you do that because you don't control what the name of the underlying field is (it's auto-generated) so there's no hook to initialize it. So now you have "auto-implemented properties".

C# code:
class Butt
{
    public int Poop { get; set; } = 12;
}
This is *exactly the same* as the following code:

C# code:
class Butt
{
    private int poop = 12;

    public int Poop
    {
        get { return poop; }
        set { poop = value; }
    }
}
Why go to all this trouble? Because writing boilerplate is boring and the C# team has really embraced the approach of "let the compiler write the boring code for you". Java has generally relied on tooling to do that for you (e.g. code-generation snippets in Eclipse). Same problem, different solutions.

The point is these are all equivalent. C# properties are just syntax over normal get/set in Java. Behaviorally it's exactly the same.

SixPabst
Oct 24, 2006

Running into a strange issue after upgrading some nuget packages in a web api solution.

I have a few methods that just return a simple integer. The response used to be just an integer like

code:
472
Not sure which package is responsible but now the same methods are returning

code:
{ "int32": 472 }
which messes up JsonConvert.DeserializeObject<int>(response)

Anyone seen this lately? I know the first response isn't valid json but would hate to have to throw in a converter for primitive types.

Edit: The solution was fixing some of the initialization code for the jsonp formatter we are using.

SixPabst fucked around with this message at 19:44 on Sep 21, 2016

Uziel
Jun 28, 2004

Ask me about losing 200lbs, and becoming the Viking God of W&W.
I'm drawing a blank on something related to list comparison.

code:
var matchingTechs = new List<Tech>();
 List<int> areaIds = GetAreaIds();

foreach (var areaId in areaIds)
{
	var areaTechs = GetAreaTechs(areaId);
	
	foreach (var areaTech in areaTechs)
	{
		var areaTechWorkAreaIds = areaTech.WorkAreas.Select(w => w.Id).ToList();
		//if area tech has ALL of the areaIds in their WorkAreas Id List, add them to matchingTechs
  		 if (areaTechAreaIds.Contains(areas)) //Does this tech have ALL of the areas in their work areas list?
                    {
                        techs.Add(areaTech);
                    }
		matchingTechs.Add(areaTech);
	}
}
For the if, what am I missing?! I am pretty sleep deprived as I would think this would be quite easy.

I tried this as:
code:
 var filteredTechs = areaTechs.Where(t => t.WorkAreas.Contains(areas));
In both cases, I get "cannot resolve method Contains". Any thoughts?

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Uziel posted:

I'm drawing a blank on something related to list comparison.

code:
var matchingTechs = new List<Tech>();
 List<int> areaIds = GetAreaIds();

foreach (var areaId in areaIds)
{
	var areaTechs = GetAreaTechs(areaId);
	
	foreach (var areaTech in areaTechs)
	{
		var areaTechWorkAreaIds = areaTech.WorkAreas.Select(w => w.Id).ToList();
		//if area tech has ALL of the areaIds in their WorkAreas Id List, add them to matchingTechs
  		 if (areaTechAreaIds.Contains(areas)) //Does this tech have ALL of the areas in their work areas list?
                    {
                        techs.Add(areaTech);
                    }
		matchingTechs.Add(areaTech);
	}
}
For the if, what am I missing?! I am pretty sleep deprived as I would think this would be quite easy.

I tried this as:
code:
 var filteredTechs = areaTechs.Where(t => t.WorkAreas.Contains(areas));
In both cases, I get "cannot resolve method Contains". Any thoughts?

What type is WorkAreas? What type is areaTechAreaIds?

Uziel
Jun 28, 2004

Ask me about losing 200lbs, and becoming the Viking God of W&W.

Ithaqua posted:

What type is WorkAreas? What type is areaTechAreaIds?
Both are List<int>.

mystes
May 31, 2006

Uziel posted:

Both are List<int>.
Are you trying to pass a list to contains?

Uziel
Jun 28, 2004

Ask me about losing 200lbs, and becoming the Viking God of W&W.

mystes posted:

Are you trying to pass a list to contains?
Yes, or figure out the equivalent if I can't do that? Intellisense is giving me the impression that I can though.

mystes
May 31, 2006

Uziel posted:

Yes, or figure out the equivalent if I can't do that? Intellisense is giving me the impression that I can though.
I don't think you can but I'm on my phone and I'm not super knowledgeable about c#. I would think you need to use the linq all method to make sure a list contains each element of another list.

aBagorn
Aug 26, 2004

Uziel posted:

Yes, or figure out the equivalent if I can't do that? Intellisense is giving me the impression that I can though.

I haven't written C# in a year or so but you should be able to use .Any() on the list instead of .Contains()

EssOEss
Oct 23, 2006
128-bit approved

Uziel posted:

Does this tech have ALL of the areas in their work areas list?

First thing that pops into my head

code:
if (areas.Intersect(techAreas).Count() == areas.Count())

dougdrums
Feb 25, 2005
CLIENT REQUESTED ELECTRONIC FUNDING RECEIPT (FUNDS NOW)
I'm not sure what 'area' and 'tech' are, but I understand that you want to add only workers that are able to work in all of the given areas to the list. I think what you want to do is something like:
code:
matchingtechs = 
	areatechs.Where(tech 
		=> areas.All(area 
			=> tech.workareas
			   .Select(workarea => workarea.id)
			   .Contains(area)));
Had it backwards ...

dougdrums fucked around with this message at 20:49 on Sep 22, 2016

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

Uziel posted:

Yes, or figure out the equivalent if I can't do that? Intellisense is giving me the impression that I can though.

To check if listA contains all items that are in listB use this:

C# code:
var aContainsB = !listB.Except(listA).Any();
Reads as "aContainsB is true if there are no elements in B that are also not in A".

Optionally, you could use HashSets since what you're actually doing is a set operation (i.e. asking "is B a subset of A?"):

C# code:
var setA = new HashSet<int>(listA);
var setB = new HashSet<int>(listB);

var isSubset = setB.IsSubsetOf(setA);
However, I would opt to just implement IsSubsetOf as an extension on IEnumerable since Except is implemented in terms of HashSets so the performance is the same (http://referencesource.microsoft.com/#System.Core/System/Linq/Enumerable.cs,785):

C# code:
public static bool IsSubsetOf<T>(this IEnumerable<T> b, IEnumerable<T> a)
    => !b.Except(a).Any();

...

//Does this tech have ALL of the areas in their work areas list?
if (areas.IsSubsetOf(areaTechAreaIds))
{
    techs.Add(areaTech);
}

Bognar fucked around with this message at 15:06 on Sep 23, 2016

Gul Banana
Nov 28, 2003

ljw1004 posted:

I asked the CLR/WinRT interop guy to reply to that thread. Is an interesting read.

it is! thanks for helping get info out there. it's really useful to know these details (like: winrtxaml subclasses have IReferenceTracker for communicating refcounted graphs to the gc, but nonxaml controls can't use it) when planning app architectures

Gul Banana
Nov 28, 2003

although i admit most of the planning comes down to "keep avoiding the tech, reevaluate each time the developers announce heroic new measures to workaround the basic problematic premise"

Uziel
Jun 28, 2004

Ask me about losing 200lbs, and becoming the Viking God of W&W.

Bognar posted:

However, I would opt to just implement IsSubsetOf as an extension on IEnumerable since Except is implemented in terms of HashSets so the performance is the same (http://referencesource.microsoft.com/#System.Core/System/Linq/Enumerable.cs,785):

C# code:
public static bool IsSubsetOf<T>(this IEnumerable<T> b, IEnumerable<T> a)
    => !b.Except(a).Any();

...

//Does this tech have ALL of the areas in their work areas list?
if (areas.IsSubsetOf(areaTechAreaIds))
{
    techs.Add(areaTech);
}
Thanks, this is what I ended up going with!

bobua
Mar 23, 2003
I'd trade it all for just a little more.

Edit: Nevermind, figured it out.

This is working really strange... I'm getting new field items added to my list, but originalkey, data, and groupid are getting overwritten on every object. I'm assuming entity framework is just trying to be efficient and not run that query again... How do I stop that?


Data and OriginalKey are [NotMapped], they're just used to help build the model for knockout.js mapping.

code:
	List<FormField> fields = new List<FormField>();
	foreach(var data in formdata)
            {
                var field = db.FormFields.FirstOrDefault(x => x.pkey == data.FieldID);
                field.OriginalKey = data.pkey;
                field.Data = data.Data;
                field.GroupID = data.GroupID;
                fields.Add(field);
            }

bobua fucked around with this message at 21:08 on Sep 23, 2016

Adbot
ADBOT LOVES YOU

EssOEss
Oct 23, 2006
128-bit approved

bobua posted:

Edit: Nevermind, figured it out.

Thanks for sharing the solutions with us.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply