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
gariig
Dec 31, 2004
Beaten into submission by my fiance
Pillbug

RICHUNCLEPENNYBAGS posted:

Do you? Frankly I think a mocked out DbContext is pretty useful in a lot of cases and with the integration test you run into consistency problems.

It depends on what you want to test. I've honestly not done much EF. Can you mock a DbContext and still get information like invalid FK like Ochowie wanted? I'm too lazy to go look up the information.

To your point about integration tests being hard. They are and might not be worth the effort. Depends on the code base

Adbot
ADBOT LOVES YOU

Smugdog Millionaire
Sep 14, 2002

8) Blame Icefrog
Just a reminder that http://dotnetpad.net exists for people who want to run their tiny .NET programs on the CLR and show the output to other people.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy
I've always used http://www.dotnetfiddle.net. It has restrictions on memory usage and CPU time, but I dunno how they stack up with .NET Pad.

Ochowie
Nov 9, 2007

gariig posted:

It depends on what you want to test. I've honestly not done much EF. Can you mock a DbContext and still get information like invalid FK like Ochowie wanted? I'm too lazy to go look up the information.

To your point about integration tests being hard. They are and might not be worth the effort. Depends on the code base

I could see some uses for it. Certainly for simulating queries or other downstream logic, or for testing error handling like RICHUNCLE mentions. It seems like unit testing a repository add method doesn't seem like it adds much value without FK checking. Originally, I foolishly thought that any non-mocked methods would revert to their regular implementation. Also, I thought that FK checking would be done by the DbSet add method instead of the SaveChanges.

ljw1004
Jan 18, 2005

rum

Knyteguy posted:

OK, well nothing that can be done then. Thanks for the help.

Apparently something can be done :) get a file without file-association, then GetThumbnailAsync(ThumbnailMode.DocumentsView), then get the pixel color at (1,1) - not at (0,0) because of the border. I'm not sure what kind of event you'd have to listen to in order to hear about changes.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

I think this is possible, but I was wondering if you guys could give me a direction to get started. I've got a large number of images provided by a third party. Some of them are either contrasty, adjusted poorly, or what have you. This means that backgrounds that should be white, are instead kind of an off-white. Here's an example image:


So what I'd like to be able to do, programmatically, is 'fix' these images so the white is actually RGB 255 white. Do you guys have any suggestions or libraries that you think are up to this?

Note: I don't have to be able to >find< them, I have another service that does this. I'd be inputting a big list of file names with weird backgrounds into whatever solution I develop.

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer

Scaramouche posted:

I think this is possible, but I was wondering if you guys could give me a direction to get started. I've got a large number of images provided by a third party. Some of them are either contrasty, adjusted poorly, or what have you. This means that backgrounds that should be white, are instead kind of an off-white. Here's an example image:


So what I'd like to be able to do, programmatically, is 'fix' these images so the white is actually RGB 255 white. Do you guys have any suggestions or libraries that you think are up to this?

Note: I don't have to be able to >find< them, I have another service that does this. I'd be inputting a big list of file names with weird backgrounds into whatever solution I develop.
If this is a one-off batch conversion I'd probably go Python or similar if you're comfortable with it because there tends to be simpler libraries for this sort of thing.

If you are going .Net, I'd just fire up nuget, search for image processing, filter by popularity and start googling library names until I found one that looked right.

The other thing to consider is whether the "blended" bits where the background meets the item are going to look okay. Try paint bucket fill on a few with the more "off" backgrounds and see if it's noticeable. If you need those bits converted properly I think you might be heading into script photoshop/gimp territory unless a there's a library that explicitly does this.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Destroyenator posted:

If this is a one-off batch conversion I'd probably go Python or similar if you're comfortable with it because there tends to be simpler libraries for this sort of thing.

If you are going .Net, I'd just fire up nuget, search for image processing, filter by popularity and start googling library names until I found one that looked right.

The other thing to consider is whether the "blended" bits where the background meets the item are going to look okay. Try paint bucket fill on a few with the more "off" backgrounds and see if it's noticeable. If you need those bits converted properly I think you might be heading into script photoshop/gimp territory unless a there's a library that explicitly does this.

Yeah, I was hoping that I could avoid a bucket fill style thing, and hopefully do a levels adjustment or something similar. e.g. set the white point/black point. I've tinkered with straight up colormap replacement and it looks kind of assy, especially when you need to color a range of values.

RICHUNCLEPENNYBAGS
Dec 21, 2010
I'm using EF and I'm wondering how to cope with performance issues that stem from having to do too many joins (basically the model looks great from a C# perspective but wasn't made with much thought to the underlying DB structure -- tight deadlines). I've given this some thought and one thing that I did think of is that I'm using a lot of entities as essentially immutable objects due to other design goals -- information is generally only ever added, rather than modifying old records. I think I might be able to make some performance gains by loading up entities into a cache (Redis? Just memory? I don't know) and using that instead.

If I pursue this what I wonder about is when to cache the data. The problem is that you end up having to descend a lot of the object graph so that the cached item is useful in a broad number of scenarios which is probably slow. Separate service? Dynamic proxies that go to the database and get new properties and update the cache (basically copying EF's lazy-loading strategy)?

Surely someone here has implemented something like this.

mortarr
Apr 28, 2005

frozen meat at high speed

Scaramouche posted:

I think this is possible, but I was wondering if you guys could give me a direction to get started. I've got a large number of images provided by a third party. Some of them are either contrasty, adjusted poorly, or what have you. This means that backgrounds that should be white, are instead kind of an off-white. Here's an example image:


So what I'd like to be able to do, programmatically, is 'fix' these images so the white is actually RGB 255 white. Do you guys have any suggestions or libraries that you think are up to this?

Note: I don't have to be able to >find< them, I have another service that does this. I'd be inputting a big list of file names with weird backgrounds into whatever solution I develop.

Not sure if this does what you're after, but I've been using ImageResizer for about two years commercially and found it to be pretty good. I'm using it for one-off resizing of A1 and A2 colour pages taken out of pdf and tiff documents, which is probably way outside what it was intended for, but it's pretty sweet and you can override quite a lot of the processing pipeline if you need custom features.

There is a paid-for version that has a plugin to do white balance adjustment which might be what you need. The source is available though, so check out \Plugins\AdvancedFilters\AutoWhiteBalance.cs in the zip.

From the docs:
Automatic white balance (alpha feature of 3.3.0)

Automatically corrects the white balance of the photo with 1 of 3 algorithms.
- area - Threshold is applied based on cumulative area at the lower and upper ends of the histogram. Much larger thresholds are required for this than SimpleThreshold.
- simple - Simple upper and lower usage thresholds are applied to the values in each channel's histogram to determine the input start/stop points for each individual channel. The start/stop points are used to calculate the scale factor and offset for the channel.
- gimp - Threshold is applied based on strangely skewed cumulative area, identical to the process used by GIMP.

epswing
Nov 4, 2003

Soiled Meat
Anyone used the mini ORM Dapper before? I'm trying to use one of its extensions to insert data, but I'm stuck on the simplest example. I'm giving it an entity and it seems to expect that there is a table of exactly the same name, instead of the plural version. Here's my Stack Overflow question: http://stackoverflow.com/questions/26287832/dapperextensions-produces-invalid-object-name-on-insert-operation

Uziel
Jun 28, 2004

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

epalm posted:

Anyone used the mini ORM Dapper before? I'm trying to use one of its extensions to insert data, but I'm stuck on the simplest example. I'm giving it an entity and it seems to expect that there is a table of exactly the same name, instead of the plural version. Here's my Stack Overflow question: http://stackoverflow.com/questions/26287832/dapperextensions-produces-invalid-object-name-on-insert-operation

You need an attribute on the org class: [Table("Orgs")]

ljw1004
Jan 18, 2005

rum

Scaramouche posted:

I think this is possible, but I was wondering if you guys could give me a direction to get started. I've got a large number of images provided by a third party. Some of them are either contrasty, adjusted poorly, or what have you. This means that backgrounds that should be white, are instead kind of an off-white.

I think you should do it all in Photoshop. Use Photoshop's "batch" functionality. There's no a-priori reason to think that an image-loading-and-processing library written in .NET will be faster than Photoshop. Indeed I'd expect Photoshop to be extremely highly optimized, native, GPU-accelerated. When you run Photoshop in batch mode it doesn't even render the images.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

mortarr posted:

Not sure if this does what you're after, but I've been using ImageResizer for about two years commercially and found it to be pretty good. I'm using it for one-off resizing of A1 and A2 colour pages taken out of pdf and tiff documents, which is probably way outside what it was intended for, but it's pretty sweet and you can override quite a lot of the processing pipeline if you need custom features.

There is a paid-for version that has a plugin to do white balance adjustment which might be what you need. The source is available though, so check out \Plugins\AdvancedFilters\AutoWhiteBalance.cs in the zip.

From the docs:
Automatic white balance (alpha feature of 3.3.0)

Automatically corrects the white balance of the photo with 1 of 3 algorithms.
- area - Threshold is applied based on cumulative area at the lower and upper ends of the histogram. Much larger thresholds are required for this than SimpleThreshold.
- simple - Simple upper and lower usage thresholds are applied to the values in each channel's histogram to determine the input start/stop points for each individual channel. The start/stop points are used to calculate the scale factor and offset for the channel.
- gimp - Threshold is applied based on strangely skewed cumulative area, identical to the process used by GIMP.

Thanks for the insight guys. I wanted to do this programmatically because I'm already doing some other processing on them (resizing, cropping, etc.) when I download them from the supplier so I figured it made sense to keep it all in one process as it were. However, mention of using an actual program to do it made me realize that I already have a (free!) program sitting on my hard drive that can handle this: FastStone Photo Resizer. It's only about one in 100 images that need processing, so I guess I can use a program to do it manually for now. If this gets any more complicated though I'm definitely going to be checking out imageresizing.net.

Knyteguy
Jul 6, 2005

YES to love
NO to shirts


Toilet Rascal

ljw1004 posted:

Apparently something can be done :) get a file without file-association, then GetThumbnailAsync(ThumbnailMode.DocumentsView), then get the pixel color at (1,1) - not at (0,0) because of the border. I'm not sure what kind of event you'd have to listen to in order to hear about changes.

Hey thanks a lot. I haven't been able to finish implementing this yet, but that'll really help bring some user customization to the app. I'll just check every start up and assign a settings variable - not too worried about changes mid run as it's for enterprise. Thanks again! This'll help it look really nice.

RICHUNCLEPENNYBAGS
Dec 21, 2010

RICHUNCLEPENNYBAGS posted:

I'm using EF Code First with a DB my application owns (like there are no other clients and for various reasons I strongly doubt there will be any that don't use my data access library).

I'm running into efficiency problems because in some places I've declared navigation properties in derived types and if you're doing queries on the supertype, you can't use the Include method to include navigation properties that only exist on subtypes. So what happens instead is you fall back to lazy loading and the database is hit every time you hit one of those properties which can be quite a few queries. You can do an OfType<> query and concatenate things together but that's messy and doesn't work too well for a lot of scenarios.

I'm thinking about a couple ways I might ameliorate it, but I'm not entirely sure I'm happy with either. Is there a better way, or, if not, which of these seems better?

1. I could move the actual declaration to the base type, using some sort of naming convention to indicate that these are "private" (not really because they have to be public, but that they should be treated as private) (e.g., _Property instead of the usual Property). I could then, on the derived type, add in a "real" property and just have the getters and setters refer to the base property. I think if I do this right I can even avoid changing the DB schema. My biggest issue with this is it's going to introduce a lot of noisy boilerplate for classes with a lot of descendants.

2. I could switch to serialization, then hook into EF's materialization to deserialize, serializing again on the save event. This certainly makes it simpler (hey, don't need to include anything at all!) and I don't really need to do queries on the contents of the fields in question. But this does go against normal sound DB design so I still have misgivings (although to be fair it's not like my Code First-generated database schema is a paragon of good DB design either).

(There's obviously the option of ditching EF but at that point I'd sooner just live with the problem because it would be a ton of work)

To keep everyone out of suspense, I ended up moving the declarations onto the base class with properties named with a special convention, then putting a "normal" unmapped property that just wrapped them on the derived types. Didn't need to change anything about the database. It works well enough.

Now my next problem is to figure out why EF is inserting, unbidden, ORDER BY statements into huge queries which cause them to time out

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy
Where is it putting the order by in the query and what does the query look like in code? I've never run into an ORDER BY statement being generated if not asked for.

SirViver
Oct 22, 2008
I'm slowly going bonkers here. Warning, :words: incoming.

Backstory: two months or so ago, I've decided that after 9ish grueling years of ASP.NET WebForms development with a little bit of WinForms sprinkled in between and constantly decreasing levels of caring about it all, I finally want to expand my horizons to include "proper", modern coding techniques and patterns. I started at creating Unit tests, as this is something I could immediately introduce to our codebase at work, at least for the parts that are easily Unit-testable without requiring years of refactoring (e.g., static utility methods/helpers, etc.). I'm under no illusion of ever covering significant portions of our humongous application with these tests, but hey, at least it's something. This has been quite successful so far, also thanks to the excellent book The Art of Unit Testing.

Recently I've decided to create a small Windows application to provide a GUI for managing our main application's DB connectivity config files. This is just a personal little side-project for learning purposes (so no harm if I just abandon it), but I figured, I might as well create something useful while I'm at it. I chose to implement this using WinForms and the MVP pattern, deciding against WPF/MVVM, because a) I'm limited to VS2010 for the time being and I'm not sure the tooling is up to handling this properly, and b) I want to keep this at baby steps - I know WinForms and its pitfalls of code-behind madness reasonably well, whereas I've simply given up at every previous attempt to learn yet another markup language (XAML) and pattern (MVVM) at the same time. I figured going this route would be a good stepping stone towards accomplishing the latter at some point. Maybe that was a mistake?

So far I've learned that while the principles behind MVP are relatively clear, everybody seems to have their own idea on how to actually implement it (even disregarding its different flavors Supervising Presenter and Passive View). While there are plenty of examples, these examples tend to be maddeningly shallow and don't even cover the most basic of functionalities (or maybe I just suck at using Google, who knows).

But let me backtrack a bit before I finally come to my question, so you can understand where I come from, my thought processes, and maybe spot where I go wrong, because clearly I'm thinking myself in a corner here somewhere. Why use MVP? To separate the UI/View from the logic of the application (via the Presenter, which is the glue between Model and View - the same thing databinding + ViewModel accomplish in MVVM). Why do that? So you can test it. Now, how to make Presenters and Model properly testable? By using IoC, most commonly implemented via DI. So far, so good, I think, but now I start running into problems. Who creates the Presenters? Who creates the Views? Actually, the main problem boils down to: how do I correctly create a child window/dialog in response to the user doing something, without having the View know too much about its Presenter (or even child View Presenters) and Model?

At the moment I've settled on the Views (Forms) creating their Presenters and supplying all* of the Presenter dependencies to the View. This gives me the freedom to just new() a child View in the appropriate place (like a click event) and get on with it, which seems like the most practical thing to do. The understanding/feeling I got was that the Presenter belongs to the View (kinda, sorta) and that the Presenter is not really responsible for opening a child View - an action that is more or less an implementation detail of the parent View. The idea being that generally the View should be replaceable and might even just be a Console implementation for all I know. On the other hand, plenty of other sources mention that this is an unrealistic goal, and in most cases you're also going to implement a new Presenter if you make a new View. Fair enough.
*Actually, that's kind of a lie, I only pass in one dependency (an application context, which at the moment holds the relevant Model objects, but I kinda plan to replace this with a proper repository pattern, not that this matters here) with the rest of the dependencies' default implementations being created in the public ctor of the Presenter - the ctor taking all the DI parameters is internal and therefore only visible to the tests (which are purely academic at this point, since I'm not doing TDD). The reason for this is that I felt kind of icky having the View know about the Model at all, and this way the knowledge is reduced/hidden as much as possible.

I've also tried using an IoC container (Simple Injector in this case) to achieve this separation, but this ends up being too limiting, as it either forces me to create the whole dependency graph at the composition root (limiting me to only a single instance of the child View assuming I inject it as dependency on the parent View - but what if I want to have multiple child views open at the same time?? Do I need a ChildViewFactory?), or forcing me to reference the IoC container from within the parent View so I can Resolve() a child View reference, but then I end up with the Service Locator pattern which just makes matters worse.

At this point I'm kinda frustrated, as I could have implemented this whole thing three times over had I done it the "classic" way (testability be damned), but that's obviously not the point of the exercise. I feel like I'm just missing something obvious and once it clicks the whole thing will resolve in unicorns and butterflies, yet at the same time everything I can find on the net either doesn't deal with such exotic matters as creating child dialogs or falls back to using the Service Locator pattern in various states of disguise :argh:.

Any advice? Bite the bullet and go WPF/MVVM? Or do similar problems exist there? :ohdear:

raminasi
Jan 25, 2005

a last drink with no ice

SirViver posted:

Any advice? Bite the bullet and go WPF/MVVM? Or do similar problems exist there? :ohdear:

It sounds like your question is about parent-child window relations, and more generally, what's supposed to be creating new Views. If that's right, WPF/MVVM doesn't really have any solutions you haven't thought of. My personal inclination is to create new Views and their associated ViewModels in parent ViewModels (so Presenters in your case), because Views aren't really supposed to do things, but I haven't seen any particularly convincing final word on the subject.

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

Bognar posted:

Where is it putting the order by in the query and what does the query look like in code? I've never run into an ORDER BY statement being generated if not asked for.

This is why statement mappers are generally better than ORMs. Total control yet still convenient.

RICHUNCLEPENNYBAGS
Dec 21, 2010

Bognar posted:

Where is it putting the order by in the query and what does the query look like in code? I've never run into an ORDER BY statement being generated if not asked for.

At the end it has an ORDER BY with every single table it queried. I don't have the code in front of me, but it's just something like .Where(o => o.field == input).Include(o => o.NavigationProperty1).Include(o => o.NavigationProperty2).Single().

Ochowie
Nov 9, 2007

So I have an f# question. Has anyone done pattern matching on .NET types using the :? operator? I'm using f# to do some financial calculations on a list of various types derived from a base class and calculations need to be performed based on the derived type. I could give each of them a calculate method and use polymorphism but I was intrigued by the ability in f# to pattern match on type.

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer

Ochowie posted:

So I have an f# question. Has anyone done pattern matching on .NET types using the :? operator? I'm using f# to do some financial calculations on a list of various types derived from a base class and calculations need to be performed based on the derived type. I could give each of them a calculate method and use polymorphism but I was intrigued by the ability in f# to pattern match on type.
It works pretty much like you'd expect but stylistically it sounds like this is when you should use polymorphism.
code:
match item with
| :? DerivedTypeA as d -> d.i + 2
| :? DerivedTypeB as d -> d.m + d.n
| _ -> 14
Without the catch-all case you'll get a compiler warning because it can't guarantee that another sub-type won't be written and you'd get a run-time exception if you do pass it one. With the catch-all case you won't get any warnings and it's not obvious to someone adding a new sub-type where in the codebase they have to add those sort of operations.

Destroyenator fucked around with this message at 13:25 on Oct 14, 2014

Ochowie
Nov 9, 2007

Destroyenator posted:

It works pretty much like you'd expect but stylistically it sounds like this is when you should use polymorphism.

I know I should, but these are POCO EF entities and I feel dirty putting what is essentially business logic right on the entity class. Transferring them to DTOs would essentially require the same kind of type checking since i would get a list of base objects and want map them to a list of DTOs.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

RICHUNCLEPENNYBAGS posted:

At the end it has an ORDER BY with every single table it queried. I don't have the code in front of me, but it's just something like .Where(o => o.field == input).Include(o => o.NavigationProperty1).Include(o => o.NavigationProperty2).Single().

This could be an "optimization" applied for .Single(), since it has to check for duplicates. Try changing it to .First().

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer

Ochowie posted:

I know I should, but these are POCO EF entities and I feel dirty putting what is essentially business logic right on the entity class. Transferring them to DTOs would essentially require the same kind of type checking since i would get a list of base objects and want map them to a list of DTOs.
Well you know the codebase better than any of us and it's partly a personal preference thing, try it out and see how it feels? Think about how often a new sub-type will be written, how many different places you'll need to put switching logic and whether you're setting a precedent (either way).

Ochowie
Nov 9, 2007

Destroyenator posted:

Well you know the codebase better than any of us and it's partly a personal preference thing, try it out and see how it feels? Think about how often a new sub-type will be written, how many different places you'll need to put switching logic and whether you're setting a precedent (either way).

Yeah this is just a personal project I'm doing for learning purposes. Part of what's bugging me is that using polymorphism with a calc method on each object seems the most obvious but it introduces weird object dependencies that I don't like and I've been struggling for a clean way of processing a heterogeneous list of derived objects in this case and the f# pattern match seems like an interesting solution.

raminasi
Jan 25, 2005

a last drink with no ice
Is there a way to use discriminated unions? One option would be to create a union parallel to the class hierarchy, which is kind of a smelly duplication of work but moves the potential runtime error to a compile-time one.

Ochowie
Nov 9, 2007

GrumpyDoctor posted:

Is there a way to use discriminated unions? One option would be to create a union parallel to the class hierarchy, which is kind of a smelly duplication of work but moves the potential runtime error to a compile-time one.

I've thought about that since I want to play around with some concepts from a paper on financial contract combinators. Buy wouldn't I still need to pattern match the original type to create the union type?

RICHUNCLEPENNYBAGS
Dec 21, 2010

Bognar posted:

This could be an "optimization" applied for .Single(), since it has to check for duplicates. Try changing it to .First().

Yeah, I did try that, and FirstOrDefault, but it did the same thing.

Anyway I tried taking out the ORDER BY clause and running the query on my own and it was still unacceptably slow (I canceled it after it ran for 20-something minutes) so obviously I need a different strategy (or to just leave the lazy loading alone for now).

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy
I don't know what your database looks like, but it's likely that you could benefit from some proper indexing. Also, what's this about lazy loading? Never lazy load, it's terrible.

Bognar fucked around with this message at 04:47 on Oct 15, 2014

Knyteguy
Jul 6, 2005

YES to love
NO to shirts


Toilet Rascal
So I'm still pretty new at this WPF/Windows Mobile Development. Can anyone tell me how I can access these in the code-behind? (Marked with a black X)


Alternatively is there a good way to share model state between XAML pages? I'm trying to create a child XAML page called from my parent XAML, and when they tap/click some data on the child window it will send that data to one of my parent window fields.

Knyteguy fucked around with this message at 18:26 on Oct 15, 2014

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Knyteguy posted:

So I'm still pretty new at this WPF/Windows Mobile Development. Can anyone tell me how I can access these in the code-behind? (Marked with a black X)


Alternatively is there a good way to share model state between XAML pages? I'm trying to create a child XAML page called from my parent XAML, and when they tap/click some data on the child window it will send that data to one of my parent window fields.

You shouldn't be touching code in your views, or at least you should barely be doing that. It sounds like you should have an instance of the child page's viewmodel in your parent viewmodel, and then the two things can interact easily. When you open up the new view, you set the datacontext to the viewmodel.

Knyteguy
Jul 6, 2005

YES to love
NO to shirts


Toilet Rascal

Ithaqua posted:

You shouldn't be touching code in your views, or at least you should barely be doing that. It sounds like you should have an instance of the child page's viewmodel in your parent viewmodel, and then the two things can interact easily. When you open up the new view, you set the datacontext to the viewmodel.

Thanks. Yea very little is in the code-behind beyond a few small UI things. OK so I have an instance of the child ViewModel as a property in the parent ViewModel, how would I share state though? As I understand it, and from my observations, a new FooViewModel class is instantiated every time a XAML page is opened. Child page is a ContentDialog though if that helps.

Edit: no that's not it either.

C# code:
if (!Frame.Navigate(typeof(FooView), BarParams))
{
    throw new Exception("Navigation Failed.");
}
Think I found it. I can likely make it work like this. I didn't think of using parameters, which should work here since it's only a couple fields I need to share.

Knyteguy fucked around with this message at 21:53 on Oct 15, 2014

RICHUNCLEPENNYBAGS
Dec 21, 2010

Bognar posted:

I don't know what your database looks like, but it's likely that you could benefit from some proper indexing. Also, what's this about lazy loading? Never lazy load, it's terrible.

Yeah, it bad and the performance is bad, but on the other hand, until I can invest some time in really fixing the database (either through fixing the indices or denormalizing or something else) I have the choice between lazy loads doing extra queries and taking like 20 seconds to load a page, or trying to include everything except it takes more than 30 minutes so it times out and you can't use the page at all. I can't really fit a proper fix into the release schedule for this version; it's gonna have to go into the next one.

My project is in the process of maturing from a quick hack job with a very aggressive deadline on an unfamiliar technology stack to a more mature thing so I'm kind of working to clean up a lot of poor practices with Entity Framework in particular now.

RICHUNCLEPENNYBAGS fucked around with this message at 00:53 on Oct 16, 2014

raminasi
Jan 25, 2005

a last drink with no ice

Ochowie posted:

I've thought about that since I want to play around with some concepts from a paper on financial contract combinators. Buy wouldn't I still need to pattern match the original type to create the union type?

code:
type DerivedWrapper =
    | DerivedWrapperA of DerivedA
    | DerivedWrapperB of DerivedB
    | DerivedWrapperC of DerivedC
code:
match whatever with
    | DerivedWrapperA(derived) -> ...
    | DerivedWrapperB(derived) -> ...
    | DerivedWrapperC(derived) -> ...
New subclasses need another DerivedWrapper case to be usable, and if their logic isn't implemented in the match statement there will be a compile error. Again, this smells, but it does solve that one particular problem.

e: I don't know anything about EF so I'm taking your word that vanilla polymorphism isn't a good idea here.

raminasi fucked around with this message at 05:20 on Oct 16, 2014

Mr Shiny Pants
Nov 12, 2012
If you are using F#, why not use a Type Provider instead of EF? Honest question.

Ochowie
Nov 9, 2007

Mr Shiny Pants posted:

If you are using F#, why not use a Type Provider instead of EF? Honest question.

I guess I could. I started with EF to do CRUD type stuff for this project so that was there before.

chippy
Aug 16, 2006

OK I DON'T GET IT
Help a brother out with a simple Winforms problem.

I want a ComboBox that you can type in, and it will autocomplete/suggest items from the list, but NOT allow free entry of something not in the list - it still has to be something from the list.

Setting the ComboBoxStyle to DropDownList comes close, but it doesn't "walk along" search; pressing a key jumps to an item whose first letter matches the key you pressed, but pressing another key will do the same again instead of matching the second character.

Is there a way of achieving this that doesn't involved hijacking OnKey or TextChanged events? This seems like something that should be easy without that much loving about.

Adbot
ADBOT LOVES YOU

Newf
Feb 14, 2006
I appreciate hacky sack on a much deeper level than you.

chippy posted:

Is there a way of achieving this that doesn't involved hijacking OnKey or TextChanged events? This seems like something that should be easy without that much loving about.

The easy way to do this involves finding a library that does it via loving about. This stackoverflow question looks like a decent start. How big is your list of selectables?

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