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
chippy
Aug 16, 2006

OK I DON'T GET IT
I want to create a factory class that takes an enum, looks up a type in a dictionary (all t ypes will be from the same superclass), and returns an instance of the type.

How the gently caress do I do this?

I've made a Dictionary with the enum as a key and a Type as value, but how do add instances of Type representing the same class, and what's the best way to instantiate them? I can't seem to find any good examples.

Adbot
ADBOT LOVES YOU

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy
If they're guaranteed to have a constructor with no parameters (or always the same parameters), you can use Activator.CreateInstance to instantiate objects from a Type object.

I'm not sure what you mean by "instances of Type representing the same class".

chippy
Aug 16, 2006

OK I DON'T GET IT

Bognar posted:

If they're guaranteed to have a constructor with no parameters (or always the same parameters), you can use Activator.CreateInstance to instantiate objects from a Type object.

I'm not sure what you mean by "instances of Type representing the same class".

OK, cool, thanks. They all have zero argument parameters.

What I mean is - in my Dictionary(Of someEnum, Type), how exactly do I create Type objects to it to create the dictionary in the first place? Type itself only seems to have a zero argument constructor.

edit: I see you can call GetType() on an object, but what if you don't have an instance of the object available?
edit: Oh, Type is abstract. So how exactly to you build a dictionary (or any collection) of types?

chippy fucked around with this message at 16:24 on Sep 2, 2015

Mr Shiny Pants
Nov 12, 2012

Bognar posted:

What does your MailboxProcessor do? Does it have any heavyweight dependencies? If it's just an object with a few methods on it and simple dependencies, then that's not gonna be a source of performance problems and pooling them isn't gonna make a significant difference.

What I'd worry more about is your concurrency model. How many requests can be executing at one time, and on how many threads? How does asynchronicity fit in? Too much creation/destruction of threads or even just too many threads can cause performance problems.

At the moment it is really simple and I've been testing it with Apache Bench, on a modest I5 I get some 7800 Requests per second with 100.000 requests and 1000 concurrent connections.

What I am trying to do is have no shared state between them and the number of threads is what the framework gives me, you can't really throttle them AFAIK.

Should I have an upper limit? Or just run with it?

chippy
Aug 16, 2006

OK I DON'T GET IT

chippy posted:

OK, cool, thanks. They all have zero argument parameters.

What I mean is - in my Dictionary(Of someEnum, Type), how exactly do I create Type objects to it to create the dictionary in the first place? Type itself only seems to have a zero argument constructor.

edit: I see you can call GetType() on an object, but what if you don't have an instance of the object available?
edit: Oh, Type is abstract. So how exactly to you build a dictionary (or any collection) of types?

It seems like typeof works in C#, but in VB I'm getting 'xxxxx' is a type and cannot be used as an expresssion'.

e: It's GetType. Panic over lads.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



I'm in a solution with multiple startup projects, a WCF service and the web site it serves data to, and Visual Studio (13) is only loading assemblies used by the web project, not the WCF project, so breakpoints in the service aren't working. I'm told the way to work around this is to add references to the service project to the web project to trick VS into loading them, too. Oh and of course this Isn't To Be Checked In, so it's a pain in the rear end that I get to manage myself.

Is that really the best/only way to do this?

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost
Run two instances of VS, one debugging the website and one debugging the WCF service.

Pixelboy
Sep 13, 2005

Now, I know what you're thinking...

Dr Monkeysee posted:

Run two instances of VS, one debugging the website and one debugging the WCF service.

This is what I do.

In other news, LinqPad 5 is out. Open your wallets. :)

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION
I'd like to implement retry logic for deadlocks, but I'm having some trouble figuring it out. The logic I've found around the place seems simple enough, but I'm not sure how to actually check for a deadlock conflict. The examples I've seen have this:
code:
if (exception.Number == 1205)
{
    // exception is a deadlock
}
But from what I can tell that's an SQL Server specific number - is that correct? The system I'm working on needs to support Firebird as well.

EssOEss
Oct 23, 2006
128-bit approved
I suppose you'll need two if-statements then!

JawnV6
Jul 4, 2004

So hot ...
I'm having an issue with timers. One is blocking another and I'm not sure if it's how I've set them up or if it's the terrible computer it's running on.

Timer1 is polling a serial port for data every 200ms. Timer 2 is launching a print with printDocument.Print() every 30s. According to the timestamps, when the print kicks off the first timer doesn't log the next sample until 2~3s have passed.

On a modern i7, this was working fine. I could see the print dialog blip up and disappear quickly. On this ancient Core2Duo the window pops up and is visible for a moment. I tried to decouple the timers by putting the .Print() call into a delegate kicked off with Invoke(), but the problem persisted.

Is there some multi-threading magic I'm missing or is this PC simply not up to the task of reading a serial port while printing a document?

gariig
Dec 31, 2004
Beaten into submission by my fiance
Pillbug

The Wizard of Poz posted:

I'd like to implement retry logic for deadlocks, but I'm having some trouble figuring it out. The logic I've found around the place seems simple enough, but I'm not sure how to actually check for a deadlock conflict. The examples I've seen have this:
code:
if (exception.Number == 1205)
{
    // exception is a deadlock
}
But from what I can tell that's an SQL Server specific number - is that correct? The system I'm working on needs to support Firebird as well.

Check out Polly for doing a lot of that plumbing code. You could just retry on all Exceptions.

JawnV6 posted:

I'm having an issue with timers. One is blocking another and I'm not sure if it's how I've set them up or if it's the terrible computer it's running on.

Timer1 is polling a serial port for data every 200ms. Timer 2 is launching a print with printDocument.Print() every 30s. According to the timestamps, when the print kicks off the first timer doesn't log the next sample until 2~3s have passed.

On a modern i7, this was working fine. I could see the print dialog blip up and disappear quickly. On this ancient Core2Duo the window pops up and is visible for a moment. I tried to decouple the timers by putting the .Print() call into a delegate kicked off with Invoke(), but the problem persisted.

Is there some multi-threading magic I'm missing or is this PC simply not up to the task of reading a serial port while printing a document?

Are you running in a GUI? This Stack Overflow question says that Timer will capture the caller's Synchronization Context.

I personally like to use Tasks and just making Tasks that never end. Just make sure to set ConfigureAwait(false) if you don't need to be on the UI thread.

gariig fucked around with this message at 21:37 on Sep 3, 2015

JawnV6
Jul 4, 2004

So hot ...
I am running in a GUI. It's charting the data it gets from the serial port, nice to look at but not totally necessary. The timers are System.Windows.Form.Timer , so with what's on that SO thread it makes sense they're executing in the UI thread.

I'll try to break that out into a task.

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

JawnV6 posted:

I'm having an issue with timers. One is blocking another and I'm not sure if it's how I've set them up or if it's the terrible computer it's running on.

Timer1 is polling a serial port for data every 200ms. Timer 2 is launching a print with printDocument.Print() every 30s. According to the timestamps, when the print kicks off the first timer doesn't log the next sample until 2~3s have passed.

On a modern i7, this was working fine. I could see the print dialog blip up and disappear quickly. On this ancient Core2Duo the window pops up and is visible for a moment. I tried to decouple the timers by putting the .Print() call into a delegate kicked off with Invoke(), but the problem persisted.

Is there some multi-threading magic I'm missing or is this PC simply not up to the task of reading a serial port while printing a document?

windows has no guarantee as to when timers will actually fire. 2-3 sec would be pretty normal if your print driver is lovely and taking all the cpu time

EssOEss
Oct 23, 2006
128-bit approved
Use System.Threading.Timer for your data-reading code to make it independent of the GUI. A few seconds of UI freeze for printing is totally normal on old PCs.

Zero The Hero
Jan 7, 2009

I've got some questions about caching lookup tables in ASP.NET. The basic issue here is, I imagine, an incredibly common one. We have a page with an edit form that loads its information from an SqlDataSource, and for every field that uses a lookup table, we have comboboxes tied to other SqlDataSources, so we can match the ID stored in the main table with the display name stored in the lookup table. This seems like something that every site does thousands of times, but we're running into efficiency issues. Profiling one of our pages showed our SELECT statements for our lookup table datasources were the biggest source of lag.

I would have thought that these things ran once for each page and didn't run again, but it looks like, when we have these comboboxes in a grid, they run for every row. But our data hasn't changed. These things get updated once a year, if that. There's got to be a way to load the lookup table into a server-side datasource that runs once when the server starts, and can be shared by every user on every page that needs this information. But for something that seems so simple, I'm having a difficult time finding any solutions through google. Can someone help point me in the right direction?

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Zero The Hero posted:

I've got some questions about caching lookup tables in ASP.NET. The basic issue here is, I imagine, an incredibly common one. We have a page with an edit form that loads its information from an SqlDataSource, and for every field that uses a lookup table, we have comboboxes tied to other SqlDataSources, so we can match the ID stored in the main table with the display name stored in the lookup table. This seems like something that every site does thousands of times, but we're running into efficiency issues. Profiling one of our pages showed our SELECT statements for our lookup table datasources were the biggest source of lag.

I would have thought that these things ran once for each page and didn't run again, but it looks like, when we have these comboboxes in a grid, they run for every row. But our data hasn't changed. These things get updated once a year, if that. There's got to be a way to load the lookup table into a server-side datasource that runs once when the server starts, and can be shared by every user on every page that needs this information. But for something that seems so simple, I'm having a difficult time finding any solutions through google. Can someone help point me in the right direction?

It's been years since I've touched webforms, but can't you tie it to an object data source? Then implement an ODS that pulls it from something in-memory that you populate whenever.

SQL data sources are awful anyway, they couple presentation and data access.

JawnV6
Jul 4, 2004

So hot ...

EssOEss posted:

Use System.Threading.Timer for your data-reading code to make it independent of the GUI. A few seconds of UI freeze for printing is totally normal on old PCs.

Thanks, this sounds like how I should've built it in the first place. It's not as simple as I was hoping as the existing timer tick just grabbed things willy nilly.

Am I correct in thinking that in the setup I should pass in everything I'll need in the callback through the state object? For instance it's writing things out to a file through a StreamWriter, my state has to carry at least that StreamWriter through? Or is it better to declare the logResults function as static?

edit: Got it working, not proud of how. Thanks for the help! throwing static volatile on the elements from the UI thread and its recording stable samples with minimal changes to the code

JawnV6 fucked around with this message at 00:23 on Sep 5, 2015

Mr Shiny Pants
Nov 12, 2012

Zero The Hero posted:

I've got some questions about caching lookup tables in ASP.NET. The basic issue here is, I imagine, an incredibly common one. We have a page with an edit form that loads its information from an SqlDataSource, and for every field that uses a lookup table, we have comboboxes tied to other SqlDataSources, so we can match the ID stored in the main table with the display name stored in the lookup table. This seems like something that every site does thousands of times, but we're running into efficiency issues. Profiling one of our pages showed our SELECT statements for our lookup table datasources were the biggest source of lag.

I would have thought that these things ran once for each page and didn't run again, but it looks like, when we have these comboboxes in a grid, they run for every row. But our data hasn't changed. These things get updated once a year, if that. There's got to be a way to load the lookup table into a server-side datasource that runs once when the server starts, and can be shared by every user on every page that needs this information. But for something that seems so simple, I'm having a difficult time finding any solutions through google. Can someone help point me in the right direction?

There is MemoryCache in .Net which has a refresh timer. You can use it to populate an Iqueryable and return from this if is not empty. I've used it in the past, works as it should.

See: http://www.codeproject.com/Articles/290935/Using-MemoryCache-in-Net-4-0

Gul Banana
Nov 28, 2003

the roslyn team have some great ideas on nonnullable types
wish them luck working out the details!

Milotic
Mar 4, 2009

9CL apologist
Slippery Tilde
I really don't think it's worth the effort. A much quicker and more appreciated fix would be the NullReferenceException mentioning either the variable name or the type of the thing that was null when it was thrown. And as they say, it creates all sorts of fun and games with generics and structs and other oddities. I also wonder if it becomes a 'virus' like async - you stick it in one place and then you've got it propagating through everywhere.

Gul Banana
Nov 28, 2003

more static checking is almost always better. the only oddity is that the check can't cover arrays- which are already unsound (covariance) and best avoided except in extreme performance requirement situations. there's no particular oddity with generics. if you use constraint object? - the default - you can use default(T), but with object you can't.

i see this as the low-cost way to get a considerable improvement to the static type system. it's not perfect, but typechecking is not feasible to make perfect. in particular, it's a LOT more feasible than this:

Milotic posted:

A much quicker and more appreciated fix would be the NullReferenceException mentioning either the variable name or the type of the thing that was null when it was thrown.

there just isn't enough information in IL to provide this information. the null check done by e.g. callvirt is looking at an untyped word on top of the register stack.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

quote:

Add a notion of safe nullable reference types T? to the language, in addition to the current ones T which are from now on non-nullable.

quote:

From a semantic viewpoint, T and T? are mostly equivalent: they are the same type in that they have the same domain of values. Specifically, because the system is far from watertight, non-nullable reference types can contain null. The only way in which they differ is in the warnings caused by their use.

I don't quite get how that would different from the existing Nullable<T> a.k.a. T? structure, which can already be used to wrap any reference type (even though that's not its intended purpose).

The only new thing in the proposal seems to be the compiler warnings for lack of null-checks / null-propagation.

LOOK I AM A TURTLE
May 22, 2003

"I'm actually a tortoise."
Grimey Drawer

NihilCredo posted:

I don't quite get how that would different from the existing Nullable<T> a.k.a. T? structure, which can already be used to wrap any reference type (even though that's not its intended purpose).

The only new thing in the proposal seems to be the compiler warnings for lack of null-checks / null-propagation.

Not sure what you mean by saying that T? can wrap any reference type. T? today is always translated to Nullable<T>, which can't be used on reference types because it has a where T : struct constraint: http://referencesource.microsoft.com/#mscorlib/system/nullable.cs,27.

My understanding is they won't actually be changing Nullable<T> to allow reference types. The change will be allowing ? to be used with any type, but it won't be translated to Nullable<T> when T is a reference type. So you're right in saying that this is mostly about the compiler warnings for unsafe dereferencing, but wrong in saying that that's the only change, because allowing the ? suffix on any type is a pretty major conceptual change in the language.

Personally I like the proposal. It's a good compromise that allows backwards compatibility but should give much better practical safeguards against boneheaded NullReferenceExceptions. Of course we'd all rather have truly non-nullable reference types in C# if we could, but I don't think there's any realistic way to retrofit that at this point.

EssOEss
Oct 23, 2006
128-bit approved
It's certainly the first proposal I have seen that does not have massive problems and one that I can imagine relatively easily making use of in practice. I will need to do some thought exercises against everyday code that I see and try to figure out how it would work. But based on first impressions, I have a good feeling here.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

LOOK I AM A TURTLE posted:

Not sure what you mean by saying that T? can wrap any reference type. T? today is always translated to Nullable<T>, which can't be used on reference types because it has a where T : struct constraint: http://referencesource.microsoft.com/#mscorlib/system/nullable.cs,27.

You're right. I was confused by a recent discussion in another thread.

quote:

Personally I like the proposal. It's a good compromise that allows backwards compatibility but should give much better practical safeguards against boneheaded NullReferenceExceptions. Of course we'd all rather have truly non-nullable reference types in C# if we could, but I don't think there's any realistic way to retrofit that at this point.

Compiler option maybe? I mean, if VB.Net can have Option Strict which basically switches it from a strongly-typed to a weakly-typed language, I don't see why you can't introduce some sort of Option Nullable.

brap
Aug 23, 2004

Grimey Drawer
Yep, even suffering through "why does this have to be optional" type issues at compile time is much better than nullreferenceexceptions at runtime. And I want it to be an opt-out thing for new projects. You get nullability warnings by default.

It's funny you call async a virus. I guess it does necessarily propagate through your call graph quite a bit--but how else could it work? The alternative is to block a thread at some point in the process. I find that much of the time it's easy to add the async keyword and wrap Task<> around my return type anyway--certainly easier than refactoring my function to consume a callback would be.

Gul Banana
Nov 28, 2003

async is one of those things which clearly isn't perfect, but is the best we have so far

maybe if an *entire* language was async, coroutine based or green-threaded, you could avoid the infecting type..?

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

Gul Banana posted:

maybe if an *entire* language was async, coroutine based or green-threaded, you could avoid the infecting type..?

Erlang?

Mr Shiny Pants
Nov 12, 2012

That is exactly what came to mind. Those Ericsson engineers, they knew a thing or two.

Gul Banana
Nov 28, 2003

that's syntactic support for CSP, not for the future monad. it works pretty nicely but it has quite different properties. a future (Task, or rather "anything with GetAwaiter") is agnostic wrt the actual concurrency model, but in erlang actors/processes are a necessity. it doesn't support something like 0-copy async io, which we have today in .net.

ninjeff
Jan 19, 2004

The nullability thing seems like a good pragmatic solution to a problem that has been resisting perfect solutions for more than a decade (in this context) now! :thumbsup:

darthbob88
Oct 13, 2011

YOSPOS
Not sure if this goes here or the SQL thread, but what's The Right Way to insert multiple rows into an SQL database, from a dataset? At present I'm just doing this, but I feel certain there must be a better method. I do fully control what goes into movieList, so I can probably get away with just string-building a command, appending new sets of values, but that still seems a bit icky.
code:
dbConnection.Open();
foreach (var movie in movieList)
            {
                var dbcommandCommand = new SQLiteCommand("insert or ignore into movies (name) values (@movieName)",
                    dbConnection);
                dbcommandCommand.Parameters.Add(new SQLiteParameter("@movieName", movie));
                try
                {
                    dbcommandCommand.ExecuteNonQuery();
                }
                catch (SQLiteException ex)
                { //TODO log ex.ErrorCode
                }
            }
dbConnection.Close();

EssOEss
Oct 23, 2006
128-bit approved
Well, in some sense it depends on your goals but The Default Way would be to just use Entity Framework, add your items to the DbSet and execute SaveChanges(). To gain some pefromance, save after every 1000 or whatever rows - doing either single row saves or massive list saves tends to be suboptimal with EF (though maybe your data size is so trivial it does not matter?).

If you need some crazy speed for a bajillion rows of data, there might be sense in doing something different using bulk import methods specific to the database engine you are using. For SQLite, I see there is some bulk import from CSV file capability in the command-line client - that would be my first point of interest. But do you really need great performance?

EssOEss fucked around with this message at 21:01 on Sep 7, 2015

darthbob88
Oct 13, 2011

YOSPOS

EssOEss posted:

Well, in some sense it depends on your goals but The Default Way would be to just use Entity Framework, add your items to the DbSet and execute SaveChanges(). To gain some pefromance, save after every 1000 or whatever rows - doing either single row saves or massive list saves tends to be suboptimal with EF (though maybe your data size is so trivial it does not matter?).

If you need some crazy speed for a bajillion rows of data, there might be sense in doing something different using bulk import methods specific to the database engine you are using. For SQLite, I see there is some bulk import from CSV file capability in the command-line client - that would be my first point of interest. But do you really need great performance?
Performance isn't really an issue, since this is just cataloging my personal media collections, of which the largest part is a couple thousand MP3s, and I only need it to run daily or thereabouts. So yeah, this is a sufficiently trivial case that unless I hand-code individual SQL statements for each item, it's not going to significantly affect performance in any case. On the other hand, my next database project is probably going to be something for work which will need some crazy speed for a bajillion rows of data, so I might as well learn to do it right on this toy project. Also, best practices get me hard.

Will modify it to use EF; was planning to significantly refactor the data structures involved anyway, so changing them to fit EF is probably not going to be a huge inconvenience.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

EssOEss posted:

I suppose you'll need two if-statements then!

I thought it was pretty clear from my post that I can figure out how to write two if statements. I was asking if there was a better way that would be more database-agnostic, because relying on some magic error number seems like a code-smell and I assumed there would be a more abstracted way to catch the deadlock. But by all means, feel free to half-understand something and then be a dick about it, you gotta get your wins somewhere right?

On another note, I posted this question on StackOverflow and I'm hoping someone here might have some advice. http://stackoverflow.com/questions/32431418/how-to-break-apart-a-list-of-nested-expressions-into-lists-of-single-level-expre/

I want to take a list like this:
code:
    var items = new List<Expression<Func<SomeModel, object>>>
            {
                x => x.Property1,
                x => x.Property1.P1ChildProperty1,
                x => x.Property1.P1ChildProperty2,
                x => x.Property2,
                x => x.Property2.P2ChildProperty1,
                x => x.Property2.P2ChildProperty2,
                x => x.Property2.P2ChildProperty3
            };
And turn it into a set of three lists like this:
code:
    List<Expression<Func<SomeModel, object>>>
    {
        x => x.Property1,
        x => x.Property2
    }

    List<Expression<Func<SomeOtherModel, object>>>
    {
        y => y.P1ChildProperty1,
        y => y.P1ChildProperty2
    }

    List<Expression<Func<YetAnotherModel, object>>>
    {
        z => z.P2ChildProperty1,
        z => z.P2ChildProperty2,
        z => z.P2ChildProperty3
    }
But I'm useless with Expressions and I can't figure it out. A StackOverflow user posted this, which comes close:
code:
var groupedItems = (from item in items
                    group item by ((MemberExpression)item.Body).Member.DeclaringType into g
                    select g.ToList()).ToList();
But it produces this set of lists:
code:
    {
        x => x.Property1,
        x => x.Property2
    }

    {
        x => x.Property1.P1ChildProperty1,
        x => x.Property1.P1ChildProperty2
    }

    {
        x => x.Property2.P2ChildProperty1,
        x => x.Property2.P2ChildProperty2,
        x => x.Property2.P2ChildProperty3
    }
So the properties have been separated based on their parents, but they haven't been "re-based" so that they are only one level deep. As I said, I'm useless with Expressions and my reading hasn't gotten me any closer so far.

putin is a cunt fucked around with this message at 00:29 on Sep 8, 2015

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

The Wizard of Poz posted:

...

So the properties have been separated based on their parents, but they haven't been "re-based" so that they are only one level deep. As I said, I'm useless with Expressions and my reading hasn't gotten me any closer so far.

You'll need to make a new expression using Expression.MakeMemberAccess.

code:
    private static List<List<LambdaExpression>> GroupExpressions(IEnumerable<LambdaExpression> exprs)
    {
        return exprs
            .Select(e => e.Body)
            .Cast<MemberExpression>()
            .GroupBy(e => e.Expression.ToString())
            .Select(g => g.Select(SimplifyMemberExpression).ToList())
            .ToList();
    }

    private static LambdaExpression SimplifyMemberExpression(Expression expr)
    {
        var memberExpr = expr as MemberExpression;
        if (memberExpr == null)
            throw new Exception("Must be member expression");

        var decType = memberExpr.Member.DeclaringType;
        var paramName = decType.Name.Substring(0, 1).ToLower();
        var param = Expression.Parameter(decType, paramName);
        var member = Expression.MakeMemberAccess(param, memberExpr.Member);
        return Expression.Lambda(member, param);
    }
Change that GroupBy however you like, but I thought using the base expression made more sense than the declaring type. To see it in action, check here: https://dotnetfiddle.net/7iPHw1

EssOEss
Oct 23, 2006
128-bit approved

The Wizard of Poz posted:

But by all means, feel free to half-understand something and then be a dick about it, you gotta get your wins somewhere right?

Aww, did I hurt the boy's feelings? Get over it.

Two if statements would be the normal way to do it. Don't overthink it - if you want a clean solution, structure your data access logic so you can either avoid deadlocks (can be tricky) or ignore them and fail if one does happen. Once you start "looking inside" database access exceptions, you are already down the slippery slope of special cases and nasty code.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

EssOEss posted:

Aww, did I hurt the boy's feelings? Get over it.

Two if statements would be the normal way to do it. Don't overthink it - if you want a clean solution, structure your data access logic so you can either avoid deadlocks (can be tricky) or ignore them and fail if one does happen. Once you start "looking inside" database access exceptions, you are already down the slippery slope of special cases and nasty code.

It's not about hurt feelings it's about wasting time. If you had posted the second part I would have very much appreciated it because even though its essentially the same conclusion, it actually helps me - and I do appreciate it, so cheers for that!

Adbot
ADBOT LOVES YOU

raminasi
Jan 25, 2005

a last drink with no ice

EssOEss posted:

Aww, did I hurt the boy's feelings? Get over it.

Being an rear end in a top hat serves absolutely no purpose here.

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