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
Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

RICHUNCLEPENNYBAGS posted:

List<T> does preserve order though? IList<T> supports indexing by number so it would be very odd not to have stable order.

That said, you can just make EF entities use ICollection<T> which is probably a more accurate reflection of what's going on.

If you have a List<T> in memory, the order will not change unless you tell it to. However, if you reload that entity from the database with EF and include that List<T> property, there are no guarantees on ordering.

Adbot
ADBOT LOVES YOU

Forgall
Oct 16, 2012

by Azathoth
Is that what they call object-relational mismatch?

Sedro
Dec 31, 2008
It's reasonable to use a list because query results are ordered.

The mismatch is when you try to pretend that foreign key relationships are object references. I've found that treating a database as sets of tuples leads to cleaner code and better performance on the order of magnitudes.

Mr Shiny Pants
Nov 12, 2012

Forgall posted:

Is that what they call object-relational mismatch?

Somewhere along the line it will execute a SQL query to retrieve the data. A recordset is always unordered.

Blue Footed Booby
Oct 4, 2006

got those happy feet

Forgall posted:

Is that what they call object-relational mismatch?

I'd say so.

brap
Aug 23, 2004

Grimey Drawer
Why is "order by" in sql then

Funking Giblet
Jun 28, 2004

Jiglightful!
For a truly ordered list, the order would need to be explicitly saved in the database in a column.
In an ORM when an entity is loaded, then the list property accessed lazily, the order stored in the database should be reflected in the list without having to issue an "order by".
This is a feature standard in nHibernate, not sure about Entity Framework.

When writing a projection though, you would need to specify your own ordering.

RICHUNCLEPENNYBAGS
Dec 21, 2010

Bognar posted:

If you have a List<T> in memory, the order will not change unless you tell it to. However, if you reload that entity from the database with EF and include that List<T> property, there are no guarantees on ordering.

Well, yeah, that's why I suggested ICollection<T>.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

This is kind of an implementation question, that I'm wondering how you guys would handle. I have to take a string up to 300 characters long and extract up to 5 values for it based on keywords in the string. Some of the values I'm matching are (always deepest level when present, e.g. I can use 'christian-crosses' but not its parent 'christian-symbols' or 'religious-symbols'):
https://images-na.ssl-images-amazon.com/images/G/01/rainier/help/icg/jewelry_item_classification_guide.html#dc_general_SubjectContent

So the way I did it way back when, when I was only concerned with 3 or 4 of them, was just a bunch of IF...THEN statements like this:
code:
Do While ListOfSubjects.Count < 5
  If title.Contains("crucifix") Then
     ListOfSubjects.add("crucifixes")
  End If
  If title.Contains("star of david") Then
     ListOfSubjects.add("star-of-david")
  End If
  (etc etc)
Loop
But if you take a look at that link, there's actually hundreds of possibilities. I could code out hundreds of IF...THENs, but that seems inefficient to me for a lot of reasons.

One idea I thought of is to make a database table (Subjects) like so:
code:
Keyword | AttributeValue
crucifix, crucifixes
star of david,star-of-david
And then do:
code:
Dim dsSubjects as DataSet = (stored proc that's basically "SELECT * FROM Subjects")
 For Each dr as DataRow in dsSubjects.Tables(0)
    If ListOfSubjects.Count > 5 then
      Exit For
    Else
      If title.contains(dr("Keyword")) then ListOfSubjects.Add(dr("AttributeValue"))
    End If
 Next
This gets me a lot of the way there, but I also have negative keywords. For example there's a 'crowns' symbol, but I don't want it to trigger for 'crown of thorns', or 'dragon' but not 'dragonfly'. This would probably be handled by adding a NegKeyword column to the database above and doing:
code:
Keyword | NegKeyword | AttributeValue
dragon,fly,dragons

and then
  If title.contains(dr("Keyword")) AndAlso Not title.contains("dr("NegKeyword")) then ListOfSubjects.Add(dr("AttributeValue"))
But then I run into multiple negative and positive keywords as well (e.g. "saint", " st ", "st.", "our lady", "o/l", "miraculous" for "saint-depictions"). So before going all the way down that path, I thought I'd ask you guys how you'd handle this. The IF...THEN way? The Keyword/Attribute database way? Or some crazy other way?

EDIT-You can ignore the special cases like month-birthstone and zodiac-sign since they're 'two step' processes that I already handle elsewhere

Scaramouche fucked around with this message at 01:17 on Jan 8, 2015

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy
Are you always searching for whole words and not subsets of words? If so, you should use a HashSet<string> or Dictionary<string, string>. Build a dictionary with all of your matching strings as keys, and the hyphenated versions as the values. Split your input string into words, then check for the existence of a key in the dictionary matching each word. Dictionary lookup is constant time so it will be a lot faster than doing a bunch of String.Contains calls, but now you'll have to worry about getting exact matches.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Bognar posted:

Are you always searching for whole words and not subsets of words? If so, you should use a HashSet<string> or Dictionary<string, string>. Build a dictionary with all of your matching strings as keys, and the hyphenated versions as the values. Split your input string into words, then check for the existence of a key in the dictionary matching each word. Dictionary lookup is constant time so it will be a lot faster than doing a bunch of String.Contains calls, but now you'll have to worry about getting exact matches.

I get what you're saying there, but I was hoping to use .Contains to cheat a bit on a regex style match so I don't have to make as many rows/keyword entries. For example .Contains("baseball") will match 'baseball', 'baseballs', 'baseball player', 'baseball glove', 'baseball hat', 'baseball bad', 'baseball pitcher', etc etc. I started the database table approach and have a first run with about 200 rows, but if I had to do exact match that would balloon up to at least 800-1000 when you take pluralization and other things into account. I also really can't split the input string very easily because it's not clear what to split on. For example split on space would work on 'dragon' but not 'star of david' or any other compound terms.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost
Are you stuck with having to use the database directly? Because it sounds like you're trying to implement full-text search which you'd be better off using a tool that already does this like Lucene or elasticsearch, or an RDBMS that supports full-text search (I believe postgres has recently added support for this). They will support stemming, pluralization, etc out of the box. This is a problem with a huge amount of edge cases and natural language-aware logic that is gonna be pretty hard to get right yourself.

Dr Monkeysee fucked around with this message at 04:31 on Jan 8, 2015

epswing
Nov 4, 2003

Soiled Meat
Any Azure gurus here? I have a strange situation. A while back I published an MVC4 app to Azure, ran it for a while, then recently decided to move to MVC5. Instead of "upgrading" to MVC5, because I know how upgrades usually go, I wiped out the MVC4 project entirely, added a fresh MVC5 project, copied over my controllers/views, and with minimal adjustments, everything worked locally. I then published the new project using the same Azure publish profile, and now I'm getting

quote:

Could not load file or assembly 'System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Some sort of assembly mismatch, which is exactly what I wanted to avoid. Is Azure holding on to some old reference/library? I'm publishing a basically brand new MVC5 project to Azure, why am I seeing assembly reference errors? Especially since the reference is looking for Razor 2, which is an MVC4 thing.

Edit1: both System.Web.Razor and System.Web.WebPages.Razor have Copy Local set to True, in case that matters.

Edit2: the internet told me to add the following to web.config to satisfy the reference, which I did
code:
  <dependentAssembly>
    <assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
    <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
  </dependentAssembly>
The error is now

quote:

Could not load file or assembly 'DotNetOpenAuth.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=2780ccd10d57b246' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Now DotNetOpenAuth.Core is definitely a pre-MVC5 thing (MVC5 is all Owin auth stuff). This makes me even more suspicious that something is hanging around in Azure that shouldn't be.

epswing fucked around with this message at 07:29 on Jan 8, 2015

EssOEss
Oct 23, 2006
128-bit approved
The purpose of bindingRedirect entries is to tell the CLR that you are OK with loading a different version of an assembly than what is actually referenced. So if you have a dependency on v1.0.0.0 you can just tell it to use v2.0.0.0 and shut up about it. This is vital because you often cannot control what versions are referenced by various libraries you include (which may have been built against older but still compatible versions of other assemblies).

The entry you added is generally the correct fix for that. Most NuGet packages add those entries automatically but sometimes they can get messed up.

The later error simply means that some assembly that you are using still references the DotNetOpenAuth.Core assembly. Perhaps some library you use was built for MVC4? Whatever the case, you can simply tell it to use the version that is available. Alternatively, you may want to investigate what exactly is referencing it and see if any corrective action is needed there (e.g. update to a newer version of a library that does not reference it).

Gul Banana
Nov 28, 2003

here's an irritating vb.net parsing ambiguity: as parentheses are used for so many things, it can't compile this code:

code:
Property F As Action
F()
although this is fine:
code:
Property F As Func(Of Integer)
Dim x = F()

epswing
Nov 4, 2003

Soiled Meat

EssOEss posted:

Alternatively, you may want to investigate what exactly is referencing it and see if any corrective action is needed there (e.g. update to a newer version of a library that does not reference it).

Thanks! How do I investigate what exactly is referencing it?

EssOEss
Oct 23, 2006
128-bit approved
.NET Reflector is my favorite tool for poking into assemblies. It provides a list of references for any assembly you open in it.

No Safe Word
Feb 26, 2005

Telerik's JustDecompile is pretty good too but by god if they aren't getting annoying with some of their nagware-like stuff. Hard to grouse about a free tool, but it used to be way less annoying :(

Munkeymon
Aug 14, 2003

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



http://ilspy.net/ also works great

Forgall
Oct 16, 2012

by Azathoth
There's also dotPeek.

ljw1004
Jan 18, 2005

rum

Gul Banana posted:

here's an irritating vb.net parsing ambiguity: as parentheses are used for so many things, it can't compile this code:

code:
Property F As Action
F()

F()() works.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Dr Monkeysee posted:

Are you stuck with having to use the database directly? Because it sounds like you're trying to implement full-text search which you'd be better off using a tool that already does this like Lucene or elasticsearch, or an RDBMS that supports full-text search (I believe postgres has recently added support for this). They will support stemming, pluralization, etc out of the box. This is a problem with a huge amount of edge cases and natural language-aware logic that is gonna be pretty hard to get right yourself.

Yeah, I have access to our SOLR/Lucene install (it drives the search on our site) but didn't want to mess around with setting it up for this. I wasn't looking for a perfect solution, just a better one than the IF...THEN chain that I had going previously. The database solution is relatively elegant for the amount of effort involved, and if I want to add/remove/change it's just a simple INSERT/UPDATE away. It falls down for complicated cases (multiple negative keywords), but for multiple positive keywords I can just add rows (e.g. Boxer, Boxing). I've actually already repurposed it for some other similar attribute name -> attribute value relationships (by adding a Type column) for about 100,000 products.

Gul Banana
Nov 28, 2003

ljw1004 posted:

F()() works.

lol what
I'd gone with F.Invoke(), so it's nice to have an alternative that doesn't betray the delegate-ness of the code - but how on earth is that parsed? one set of parens is the invoke, and the other.. a unit expression it's applied to? empty generic clause??

Gul Banana
Nov 28, 2003

ok, i've got it: VB.NET has indexed properties. you can write
ReadOnly Property F(s As String) As String

F("s") would invoke the getter. by analogy, you can call an UNindexed property like: F(). then the subsequent () are just the delegate invocation...

wwb
Aug 17, 2004

Scaramouche posted:

Yeah, I have access to our SOLR/Lucene install (it drives the search on our site) but didn't want to mess around with setting it up for this. I wasn't looking for a perfect solution, just a better one than the IF...THEN chain that I had going previously. The database solution is relatively elegant for the amount of effort involved, and if I want to add/remove/change it's just a simple INSERT/UPDATE away. It falls down for complicated cases (multiple negative keywords), but for multiple positive keywords I can just add rows (e.g. Boxer, Boxing). I've actually already repurposed it for some other similar attribute name -> attribute value relationships (by adding a Type column) for about 100,000 products.

Is sql fulltext and option? That could get you there without messing about with SOLR.

epswing
Nov 4, 2003

Soiled Meat
Jesus loving Christ. In a WPF application, I have an html string, and I want to render and display it to the user, and allow them to print what they see in landscape. Why is this the hardest loving problem in the history of problems on earth?

bpower
Feb 19, 2011

epalm posted:

Jesus loving Christ. In a WPF application, I have an html string, and I want to render and display it to the user, and allow them to print what they see in landscape. Why is this the hardest loving problem in the history of problems on earth?

Now you know how St. Joseph of Sevastopol felt :colbert:

edit: \/\/\/ just some dude I made up :shobon: ,but you can imagine him getting in quite the pickle.

bpower fucked around with this message at 19:50 on Jan 9, 2015

Munkeymon
Aug 14, 2003

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



epalm posted:

Jesus loving Christ. In a WPF application, I have an html string, and I want to render and display it to the user, and allow them to print what they see in landscape. Why is this the hardest loving problem in the history of problems on earth?

I ended up punting that sort of thing to the browser when I had to try to figure it out a couple years ago :smith:

Rooster Brooster
Mar 30, 2001

Maybe it doesn't really matter anymore.

bpower posted:

Now you know how St. Joseph of Sevastopol felt :colbert:

I want to get this joke but Google is failing me :(

Inverness
Feb 4, 2009

Fully configurable personal assistant.
WPF makes easy things hard and hard things easy.

Blasphemeral
Jul 26, 2012

Three mongrel men in exchange for a party member? I found that one in the Faustian Bargain Bin.

Inverness posted:

WPF makes easy things hard and hard things easy.

This is completely true.

The dumbest part is, though, that with a product as old as WPF is now, they should have fixed all of those "hard" things ages ago. Example: Having control events that that can't simply data-bind to your view-model by default? Seriously, guys, WTF?



Edit: Disclaimer, I am using 2012. Maybe they've fixed it since. (But I doubt it.)

wilderthanmild
Jun 21, 2010

Posting shit




Grimey Drawer
When I switched from winforms to WPF, my ability to estimate time on projects went way out of whack. Lots of stuff that I'd usually expect to take ages is trivial and easy and some stuff that seems really basic and easy is nigh impossible. It feels like a couple controls were just given up on. The Browser and Datagrid have both been nightmares to me at times. All things considered though, I loving love WPF after working with winforms for an unfortunately long time.

epalm posted:

Jesus loving Christ. In a WPF application, I have an html string, and I want to render and display it to the user, and allow them to print what they see in landscape. Why is this the hardest loving problem in the history of problems on earth?

I had a similar problem where I was trying to display a formatted html version of various things my company works with. I ended up giving up and just going with a completely different solution where I didn't have to render HTML at all.

Calidus
Oct 31, 2011

Stand back I'm going to try science!
I generally just gave up on WPF when trying to switch form WinForms, and went straight to MVC web apps.

RICHUNCLEPENNYBAGS
Dec 21, 2010

ljw1004 posted:

F()() works.

Oh, of course.

epswing
Nov 4, 2003

Soiled Meat
This nice StackOverflow answer contains what VS 2012 files should typically be ignored by Mercurial. Among them is *.pubxml under the comment "## Publish Web Output". Makes sense, you don't want that sensitive information in version control.

What comes along with your public profile however is a line in your csproj file like
code:
<None Include="Properties\PublishProfiles\myprofile.pubxml" />
So myprofile.pubxml isn't under version control, but there's a reference to it hanging around in csproj.

Is there a nice way to handle this?

aBagorn
Aug 26, 2004

Calidus posted:

I generally just gave up on WPF when trying to switch form WinForms, and went straight to MVC web apps.

This is what I did too. And now I'm further down the web rabbit hole with all the JS frameworks with Web API 2 backends.

epswing
Nov 4, 2003

Soiled Meat
Let's say I have a standard EF backed MVC app, with the standard Product class, which has Name and Price properties. I've added the necessary annotations to indicate at the DB level that Name must be at most 40 characters, and Price must be greater than 0. I'm also doing The Right Thing by using Automapper to map Product objects to ProductEditDto objects for MVC consumption. In order to take advantage of client-side validation which spots problems right away and notifies the user via JS, I must also decorate ProductEditDto with a second set of annotations to ensure Name length and Price value are acceptable.

Now I need to keep two sets of validation up to date. How do I avoid this?

EssOEss
Oct 23, 2006
128-bit approved
I have never found a non retarded way to do that, so good luck. In all my projects I simply end up with duplicate validation logic. I have tried various other approaches but they just turn the mess into a different type of mess in my experience.

Wardende
Apr 27, 2013
You could create custom validation attributes that implement your specific validation logic (e.g, NameMaxLengthAttribute which is really a MaxLengthAttribute(40)) and apply them to both your data models and view models. This means you have loads of sorta useless attribute classes floating around, but at least you wouldn't need to keep two sets of constants in sync.

Adbot
ADBOT LOVES YOU

mastersord
Feb 15, 2001

Gold Card Putty Fan Club
Member Since 2017!
Soiled Meat
I apologize in advance for sounding like an inexperienced moron. I am in the process of trying to upgrade all our in-house code from VB6 to VB.NET and since we're so small, no one really knows anything about visual Studio past VS99 or whatever was the last VB6 release. I am trying to catch up on the last 10-15 years of advances on my own.

Why does it seem like everyone is making web apps as opposed to local apps? In my shop we have no need for any special internet applications outside of the browser and with HIPAA we have little to no reason to unnecessarily expose our data to the internet more than required.

Am I mis-interpreting what MVC does?

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