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.
 
  • Locked thread
Sockser
Jun 28, 2007

This world only remembers the results!




gariig posted:

Gotcha! Tried PowerShell? You can run PowerShell from your application and use the Set-WinSystemLocale with it.

Hm. This combined with the other setup stuff I need to do means I may just keep it as separate machines for separate languages. Was hoping it'd be something simple like setting a registry key or an env var or something.

Adbot
ADBOT LOVES YOU

Dirk Pitt
Sep 14, 2007

haha yes, this feels good

Toilet Rascal
I am building another windows phone app and want to try more unit and integration testing in my Core PCL. What is the mock framework many use? I wish my boss let me dabble in unit testing but he won't so I have to read and do so on my spare time.

Osherove seems to recommend nsub in The Art of Unit Testing but I don't know if I am sold on that just yet.

Dietrich
Sep 11, 2001

Dirk Pitt posted:

I am building another windows phone app and want to try more unit and integration testing in my Core PCL. What is the mock framework many use? I wish my boss let me dabble in unit testing but he won't so I have to read and do so on my spare time.

Osherove seems to recommend nsub in The Art of Unit Testing but I don't know if I am sold on that just yet.

I recommend Moq.

Gimpalimpa
Jun 27, 2004
Title text?
Hi, I have a lot of VB SSIS jobs that are more VB than SSIS. They run on a scheduled SQL server. I will randomly get an error of: "Object variable or With block variable not set." on some of them at random points in time. My predecessors ignore these errors because eventually the jobs will run without an error. I want to figure out the cause of it. I've narrowed it down to the following code:

code:
Dim cn As OleDbConnection
        Try
            cn = New OleDbConnection(Dts.Connections("MyDestinationConnection").ConnectionString)
            cn.Open()
            strErrors += "Checkpoint 7" & Environment.NewLine
            'get the table as an empty dataset
            Dim da As New OleDbDataAdapter("SELECT * FROM tbldFoo WHERE 1 = 0", cn)
            Dim ds As New DataSet
            strErrors += "Checkpoint 8" & Environment.NewLine
            'Fill schema
            da.FillSchema(ds, SchemaType.Source, "tbldFoo")
            da.Fill(ds, "tbldFoo")
            strErrors += "Checkpoint 9" & Environment.NewLine
            'Command Builder
            Dim cmdBuilder As New OleDbCommandBuilder(da)
            da.InsertCommand = cmdBuilder.GetInsertCommand()
            da.UpdateCommand = cmdBuilder.GetUpdateCommand()
            da.DeleteCommand = cmdBuilder.GetDeleteCommand()
            strErrors += "Checkpoint 10" & Environment.NewLine
            Dim strDelete As String = "DELETE FROM tbldFoo WHERE SystemId='" & SystemId & "' & _
			 AND Admin='" & Admin & "' and Technote='" & Technote & "'" 
            Dim cmd As New OleDbCommand(strDelete, cn)
            strErrors += "Checkpoint 11" & Environment.NewLine & strDelete & cn.State.ToString & Environment.NewLine
            cmd.ExecuteNonQuery()  ;it craps out here.
	    strErrors += "Checkpoint 12" & Environment.NewLine
		'more Stuff
	catch ex as exception
		strErrors += "lots of other stuff to help troubleshoot that doesn't apply to this post"
	finally
		if not cn is nothing then
			cn.close()
		end if
	end try
The result is the following:

quote:

Object variable or With block variable not set.
....
Checkpoint 7
Checkpoint 8
Checkpoint 9
Checkpoint 10
Checkpoint 11

DELETE FROM tbldFoo WHERE SystemId='foo' AND Admin='foo' and Technote='<a valid and normal string>'Open

I've been trying to figure this out for a solid week. The people in my office don't care and it's difficult to reproduce the error. My guess is that it's related to the server being overloaded, but nothing about the error message indicates that. I figured the connection might be getting closed, but my connection state shows up as open in the error message. Also, I am very wierded out that it's not throwing an exception since my catch statement isn't picking anything up.
Any ideas, anyone?

*edit* whoops tables.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug
First off, this is absolutely horrible and you should immediately replace it with a parameterized query, and then find every other instance of building SQL via string concatenation and do the same. SQL injection vulnerabilities are a huge problem and are absolutely trivial to avoid.

code:
            Dim strDelete As String = "DELETE FROM tbldFoo WHERE SystemId='" & SystemId & "' & _
			 AND Admin='" & Admin & "' and Technote='" & Technote & "'" 
That actually might solve your problem... I wouldn't be surprised if the problem only pops up when your "Technote" is something containing unescaped data that creates a bad SQL statement, like a string containing a single quote or something like that.

You should also probably wrap up your disposables (the connection, the data adapter, etc) in using blocks, although that's not going to be the source of your problem here.

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

Gimpalimpa posted:

Also, I am very wierded out that it's not throwing an exception since my catch statement isn't picking anything up.
Any ideas, anyone?

*edit* whoops tables.

It could be from the lower case exception. I couldn't get VS2013 to allow a lower case exception instead of Exception. VB.NET can be a little forgiving with errors like this. I think Ithaqua is correct about the string concatenation of Technote is causing you an invalid SQL string. Have you tried running one of the delete statements that causes an error in SQL Server Management Studio?

Gimpalimpa
Jun 27, 2004
Title text?
Thanks for the responses.

quote:

Technote could be bad

I can copy/paste the SQL delete statement from my error log and it runs without a problem.

quote:

It could be from the lower case exception.

I've had other exception types get caught, so I don't think this is the case.

gariig
Dec 31, 2004
Beaten into submission by my fiance
Pillbug
I would just try a code cleanup. Pull the delete to it's own method, parameterize the query, and open a new connection for the delete. I generally try not to share a connection because I've had it lead to some strange stuff occurring. Dump the finally and move to Using statements. Are you logging the Exception.ToString? If not that gives you a stack trace and inner exceptions. Make sure your Catch isn't throwing an Exception that could be hiding the real Exception.

Mr Shiny Pants
Nov 12, 2012

wwb posted:

We've got a little project that involves reading a bunch of PDFs and making them searchable. We can handle the whole "take bags of text and make it searchable" pretty easily but we are having some trouble with the reading PDFs end of the equation.

We've tried using PdfTextract which is a pretty thin wrapper on the last free version of PdfSharp before they went commercial with limited success. We have also tried Docotic.Pdf which seems to work but I really hate to pay $1k to read PDFs. Is there anything else out there that is reliable for less or better yet free*?

* money isn't really the problem, all the overhead of dealing with license components rubs me wrong and is a pain in the rear end with the CI setup we've got.

Well for making PDFs searchable Abby Finereader OCR is the best. For free: maybe the Adobe Ifilters for PDF?

gnatalie
Jul 1, 2003

blasting women into space

Gimpalimpa posted:

Hi, I have a lot of VB SSIS jobs that are more VB than SSIS. They run on a scheduled SQL server. I will randomly get an error of: "Object variable or With block variable not set." on some of them at random points in time.
...

Object variable or With block variable not set.
....
Checkpoint 7
Checkpoint 8

I'm wondering about this line of code:
Visual Basic .NET code:
strErrors += "Checkpoint 7" & Environment.NewLine
Since it looks like your variable related exception is being thrown sometime before the try/catch block, is it possible to narrow down the location a bit and show us the 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
I wonder if someone can help me with this. As someone pretty new to .NET and C# I'm having a lot of trouble understanding how to get MVC5's authentication stuff working with an existing database of usernames and passwords. Basically I'm needing to write a small web site that will connect to an existing database and authenticate against a username and password stored within that database. Being so new to all this I'm needing something of a crash course but I'm having a lot of trouble wrapping my head around the complexity of claims based authentication. All I really want is to check the username and password in the database and return whether the credentials were valid, but it seems incredibly complicated to do this, OR I haven't been able to find the magic resource that will give me the information I'm needing.

Can anyone help at all with this?

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

Gnack posted:

I wonder if someone can help me with this. As someone pretty new to .NET and C# I'm having a lot of trouble understanding how to get MVC5's authentication stuff working with an existing database of usernames and passwords. Basically I'm needing to write a small web site that will connect to an existing database and authenticate against a username and password stored within that database. Being so new to all this I'm needing something of a crash course but I'm having a lot of trouble wrapping my head around the complexity of claims based authentication. All I really want is to check the username and password in the database and return whether the credentials were valid, but it seems incredibly complicated to do this, OR I haven't been able to find the magic resource that will give me the information I'm needing.

Can anyone help at all with this?

This has all of the interfaces you need to implement. I couldn't find a good example that implements it's own password hashing but I think that should point you in the right direction

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

gariig posted:

This has all of the interfaces you need to implement. I couldn't find a good example that implements it's own password hashing but I think that should point you in the right direction

Wow, that looks like the exact resource I needed - thank you so much.

mortarr
Apr 28, 2005

frozen meat at high speed

Gnack posted:

Words about asp.net MVC authentication...

Not sure if this is relevant for your situation, but once you have the info on authentication, I've used fluent security for the authorisation stuff in MVC projects, as a way to record what roles have what access in a centralised location, rather than spread out as attributes over all my controllers etc.

Here's a basic example from their getting started guide...

code:
SecurityConfigurator.Configure(configuration =>
{
	// Let FluentSecurity know how to get the authentication status of the current user
	configuration.GetAuthenticationStatusFrom(() => HttpContext.Current.User.Identity.IsAuthenticated);

	// This is where you set up the policies you want FluentSecurity to enforce on your controllers and actions
	configuration.For<HomeController>().Ignore();
	configuration.For<AccountController>().DenyAuthenticatedAccess();
	configuration.For<AccountController>(x => x.ChangePassword()).DenyAnonymousAccess();
	configuration.For<AccountController>(x => x.LogOff()).DenyAnonymousAccess();
});
I'm using a combination of Active Directory for authentication and SQL for user/role mapping, so membership can be controlled by a super-user of the app (without bothering the IT helpdesk if I had gone with AD roles). It works by injecting role membership into a custom user object, and using fluent security to validate the user/role/controller-method combo, then bailing to an access-denied screen if they're not allowed.

I'm not a pro at MVC security, and this is for an internal app, but it seems to work really well and I found the docs to be pretty good too.

Uziel
Jun 28, 2004

Ask me about losing 200lbs, and becoming the Viking God of W&W.
Is there a better way than IValidatableObject to do conditional validation of a model in MVC5?

My specific example is that I have a ModemModel, and it has an account number as a required field. Depending on which billing system it is being added to, the length of the account number is different.

Also, if the modem is an EMTA (modem and phone), then a second MAC address field is required. If it isn't an EMTA, no second MAC is needed.

I was hoping to just keep everything in one form with one model if possible, with the options for billing system and EMTA/Not EMTA as radio buttons.

Gimpalimpa
Jun 27, 2004
Title text?
Update - Today I had a wonderful moment where it did this when I was in debug mode today. The job is throwing a query timeout exception at that point and then something further down in my code is screwing it up to a "object not set" error message. I was stepping through too quickly to catch where, but it's nice to know the core cause.

Drythe
Aug 26, 2012


 
Quick question that seems like it should be simple.

We have a drop down for our help desk system to associate the issue with a category. Now over the years the categories list seems to have gotten out of hand and I've been tasked with trimming it down. Is there a way for me to remove an item from the drop down without throwing an error when someone tries to look at an old problem of one of the removed categories. I would like to do this as minimally as possible so I don't know if there's a way to get the drop down to hide the item but the value still be there.

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

Drythe posted:

Quick question that seems like it should be simple.

We have a drop down for our help desk system to associate the issue with a category. Now over the years the categories list seems to have gotten out of hand and I've been tasked with trimming it down. Is there a way for me to remove an item from the drop down without throwing an error when someone tries to look at an old problem of one of the removed categories. I would like to do this as minimally as possible so I don't know if there's a way to get the drop down to hide the item but the value still be there.

I would just get the list of currently approved categories. When loading a problem I'd check to see if it's assigned category is in the list and if not add it. So the most anyone will see is one incorrect category which is the one the current problem is assigned to.

You could also fix the data. Map the old categories to new ones but there's not always a 1:1 so that might be too much work.

Drythe
Aug 26, 2012


 

gariig posted:

I would just get the list of currently approved categories. When loading a problem I'd check to see if it's assigned category is in the list and if not add it. So the most anyone will see is one incorrect category which is the one the current problem is assigned to.

You could also fix the data. Map the old categories to new ones but there's not always a 1:1 so that might be too much work.

I was going to do that, was just wondering if the control was able to do that on it's own.

A lot of these stupid categories look like they were used once or twice....five years ago.

Edit: Why the gently caress is there three places the categories get bound at??? Working on this system is just....:suicide:

Drythe fucked around with this message at 19:10 on Feb 26, 2014

ManoliIsFat
Oct 4, 2002

Drythe posted:

Quick question that seems like it should be simple.

We have a drop down for our help desk system to associate the issue with a category. Now over the years the categories list seems to have gotten out of hand and I've been tasked with trimming it down. Is there a way for me to remove an item from the drop down without throwing an error when someone tries to look at an old problem of one of the removed categories. I would like to do this as minimally as possible so I don't know if there's a way to get the drop down to hide the item but the value still be there.
I'd say you add an "active" or "active in menu" column to the list of categories, and then only show the active categories in this dropdown. You'll have whatever referential integrity in your DB, but your menu won't be cluttered with selections no one makes anymore.

(But to be honest, I don't even know if there's a db involved here)

Macichne Leainig
Jul 26, 2012

by VG
WPF questions ahoy.

I have a button that looks like this:



I have an event set up to notify the user an error has occurred. The event is already wired up and a little label shows up when an error has occurred. I want to get rid of this label and make the image in this button flash instead. I know how to write a infinitely repeating storyboard, but not quite how to change the image and make it so the storyboard is tied to this event and is stopped when the button is clicked. Anyone super good at WPF?

Bonus if we can set it up so the button flashes a different color for each log4net category (blue for info, green for debug, yellow for warnings, et cetera.) The event handles categories as well, so it's really just storyboarding this poo poo out that has me confused.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Tha Chodesweller posted:

Bonus if we can set it up so the button flashes a different color for each log4net category (blue for info, green for debug, yellow for warnings, et cetera.) The event handles categories as well, so it's really just storyboarding this poo poo out that has me confused.

Usability quibble: Flashing is generally annoying (remember the <blink> tag in Netscape?). Using colors to convey information that's not conveyed elsewhere is a nightmare for colorblind people, such as myself. In my world, some reds look brown or black. Some greens look yellow. It's really annoying.

Milotic
Mar 4, 2009

9CL apologist
Slippery Tilde
Over the course of the next 6 months, I'm doing an in-place migration of an internal webapp from Silverlight to ASP.NET MVC (+some front end js framework). Given it's an internal app, and we use Active Directory, is there much value to be had by using ASP.NET Identity. Especially if I'm keen to not use the Entity Framework based persistence layer part of ASP.NET Identity (we're moving away from using EF in favour of just raw ADO.NET)?

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer

Uziel posted:

Is there a better way than IValidatableObject to do conditional validation of a model in MVC5?

My specific example is that I have a ModemModel, and it has an account number as a required field. Depending on which billing system it is being added to, the length of the account number is different.

Also, if the modem is an EMTA (modem and phone), then a second MAC address field is required. If it isn't an EMTA, no second MAC is needed.

I was hoping to just keep everything in one form with one model if possible, with the options for billing system and EMTA/Not EMTA as radio buttons.
http://foolproof.codeplex.com will get you most of the way there, I think conditional length might be an issue though. The ones it does support ([RequiredIf, "OtherField", EqualTo, ETMA]) get javascript and server side validation and it's not too hard to add your own validation rules in.

Uziel
Jun 28, 2004

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

Destroyenator posted:

http://foolproof.codeplex.com will get you most of the way there, I think conditional length might be an issue though. The ones it does support ([RequiredIf, "OtherField", EqualTo, ETMA]) get javascript and server side validation and it's not too hard to add your own validation rules in.
Thanks. I came across that when looking around but found that just implementing IValidatableObject was easy. The client side portion took some time to get right but it turned out like this:
C# code:
 public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            if (IsEmta && string.IsNullOrWhiteSpace(EmtaMacAddress))
                yield return new ValidationResult("If the modem is an EMTA, an EMTA MAC is required.", new[] {"EmtaMacAddress"});
            if (IsCsg && AccountNumber.Length != 16)
                yield return new ValidationResult("CSG Account Number must be 16 digits.", new[] { "AccountNumber" });
            if (!IsCsg && AccountNumber.Length != 14)
                yield return new ValidationResult("Amdocs Account Number must be 14 digits.", new[] { "AccountNumber" });
        }
JavaScript code:
$(function () {
            $('#addModem').validate();
            $('#EmtaMacAddress').rules('add', {
                required: {
                    depends: function (el) { return $('#IsEmta').prop("checked"); }
                },
                messages: {
                    required: "If the modem is an EMTA, an EMTA MAC is required.",
                }
            });
            $('#AccountNumber').rules('add', {
                minlength: function (el) {
                    if ($('#csg-true').prop("checked")) {
                        return 16;
                    } else {
                        return 14;
                    }
                },
                messages: {
                    minlength: function (el) {
                        if ($('#csg-true').prop("checked")) {
                            return "Account number must be 16 digits";
                        } else {
                            return "Account number must be 14 digits";
                        }
                    }
                }
            });

Macichne Leainig
Jul 26, 2012

by VG

Ithaqua posted:

Usability quibble: Flashing is generally annoying (remember the <blink> tag in Netscape?). Using colors to convey information that's not conveyed elsewhere is a nightmare for colorblind people, such as myself. In my world, some reds look brown or black. Some greens look yellow. It's really annoying.

That's fair. I'll just make the label a little less lovely, have it look like a speech bubble coming from the error button or something.

edit:

How's this? (Placeholder text, it's a little more verbose when something actually happens.)

Macichne Leainig fucked around with this message at 16:52 on Feb 27, 2014

Mr. Crow
May 22, 2008

Snap City mayor for life
Question for people who have worked on Android and Windows 8 (maybe this should be in the general thread..), having a hard time finding comparisons on the two that aren't consumer related; anyone have thoughts on one over the other from a tablet developmental environment standpoint? Or is better googling than myself for technical comparisons?

wwb
Aug 17, 2004

Milotic posted:

Over the course of the next 6 months, I'm doing an in-place migration of an internal webapp from Silverlight to ASP.NET MVC (+some front end js framework). Given it's an internal app, and we use Active Directory, is there much value to be had by using ASP.NET Identity. Especially if I'm keen to not use the Entity Framework based persistence layer part of ASP.NET Identity (we're moving away from using EF in favour of just raw ADO.NET)?

I haven't spent any measurable time with the new identiy framework though it looks good and I don't see why you couldn't easily roll your own plumbing for the raw ADO.NET bits.

I have done a number of AD backed authentication schemes in the past. Generally we found that the most successful model was to let AD be the authenticator and handle authorization in the app rather than also ride AD groups for that. In that context it often made sense to ride parts of the membership providers even though the users weren't necessarily living with in SQL server.


quote:

Question for people who have worked on Android and Windows 8 (maybe this should be in the general thread..), having a hard time finding comparisons on the two that aren't consumer related; anyone have thoughts on one over the other from a tablet developmental environment standpoint? Or is better googling than myself for technical comparisons?

More conjecture and stories from drinking with other devs than anything but from what I hear wp8 is much easier to develop upon from a tooling standpoint at least -- you've got Visual Studio and all that and most of your knowlege / tooling / skills should transfer directly. Android emulators are especially slow and buggy which is probably the main pain point. The other pain point is that the wide assed variety of android devices / skins / versions means you will have all kinds of wierd devices specific bugs to hunt down. WP is a much more limited universe so you don't have to fight that as much.

One advantage android has is there is a lot more android dev going on so online resources should be better in general.

Tooling-wise, android originally used eclipse but I've heard very good things about jetbrains Android Studio.

RICHUNCLEPENNYBAGS
Dec 21, 2010

wwb posted:

I haven't spent any measurable time with the new identiy framework though it looks good and I don't see why you couldn't easily roll your own plumbing for the raw ADO.NET bits.

I have; the current project we're working on uses it because we were time-constrained.

You get users, hashed passwords, roles, and claims, which is nice. But there are some weird things (like you don't have to have a password for an account) and you're going to end up doing some stuff on your own unless you don't need to have password reset or changing usernames or a couple other features.

I think it would be miserable or at least pointless if you aren't using EF though.

RangerAce
Feb 25, 2014

Milotic posted:

Over the course of the next 6 months, I'm doing an in-place migration of an internal webapp from Silverlight to ASP.NET MVC (+some front end js framework). Given it's an internal app, and we use Active Directory, is there much value to be had by using ASP.NET Identity. Especially if I'm keen to not use the Entity Framework based persistence layer part of ASP.NET Identity (we're moving away from using EF in favour of just raw ADO.NET)?

Yeah, I don't see why you'd want to use Identity if you're not using EF. I mean, you can get some scaffolding off it, but I think you can get that anyway out of MVC. I assume you're not going with EF because you'd have to refactor your DB schema for it? I've actually been thinking about migrating us to EF because I have a lot of low-experience junior devs working for us, and I want to remove learning SQL as a requirement for working on our backend code. But, then I'm worried about taking too much of a performance hit, etc. So, curious about your findings/thoughts.

RICHUNCLEPENNYBAGS
Dec 21, 2010
To use EF and not end up with an unmaintainable mess you have to know how databases work and what EF is doing under the hood so I don't think you're going to remove the need for them to understand SQL entirely (even if you don't care how it ends up you need to have relationships on your objects going both ways to get cascading delete under certain circumstances and if you don't bother to do that you'll just get EF errors when you try to delete stuff which are gonna be a pain).

I don't know much about the performance characteristics if you have crazy scale. My project doesn't have gazillions of users. I don't notice the overhead.

But anyway, my point is I would recommend it for people who already know SQL but don't want to bother hand-mapping everything, not people who don't know anything about SQL and are hoping to avoid learning. I'm using Code First though; I guess some of these things might play out differently with DB First.

RICHUNCLEPENNYBAGS fucked around with this message at 01:35 on Feb 28, 2014

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

RangerAce posted:

I've actually been thinking about migrating us to EF because I have a lot of low-experience junior devs working for us, and I want to remove learning SQL as a requirement for working on our backend code. But, then I'm worried about taking too much of a performance hit, etc. So, curious about your findings/thoughts.

Bad idea. SQL is still an important skill, and one of your junior devs is eventually going to have to write a query against a database outside the context of EF, or troubleshoot why EF is generating a totally stupid query.

I wouldn't worry about the performance of ORMs over crafting your own SQL. They're pretty smart about it, and if you get a query that's generating some sort of weird, slow SQL, you can always map a stored procedure to a model.

Of course, I don't like EF because it practically begs you to misuse it and expose data access objects outside of the data access layer.

mortarr
Apr 28, 2005

frozen meat at high speed

RICHUNCLEPENNYBAGS posted:

...

But anyway, my point is I would recommend it for people who already know SQL but don't want to bother hand-mapping everything, not people who don't know anything about SQL and are hoping to avoid learning. I'm using Code First though; I guess some of these things might play out differently with DB First.

I'd second this, as a seasoned user of code-first, there's no way I'd let junior devs with or those with no or little SQL experience do anything significant using EF code-first without a senior watching them closely.

I've never used the EF designers and visual modelling tools, and a good third of my EF work deals with maintenance/brown-fields dev in existing inhouse and vendor db's, so can't speak to true green-fields or single-db-only dev situations.

RICHUNCLEPENNYBAGS
Dec 21, 2010

mortarr posted:

I'd second this, as a seasoned user of code-first, there's no way I'd let junior devs with or those with no or little SQL experience do anything significant using EF code-first without a senior watching them closely.

I've never used the EF designers and visual modelling tools, and a good third of my EF work deals with maintenance/brown-fields dev in existing inhouse and vendor db's, so can't speak to true green-fields or single-db-only dev situations.

That definitely applies to greenfield and single-DB stuff too.

RICHUNCLEPENNYBAGS fucked around with this message at 04:56 on Feb 28, 2014

Cancelbot
Nov 22, 2006

Canceling spam since 1928

Is there a way I can do null-free C# cleanly? I'm experimenting and this is my current implementation;

I have the following object:
code:
// interface
public interface IMatchResult
{
    int MatchResultId { get; set; }
    IFixture Fixture { get; set; }
    int HomeScore { get; set; }
    int AwayScore { get; set; }
    bool IsDraw { get; }
    IClub Winner { get; }
}

// implementation
public class MatchResult : IMatchResult
{
    private IFixture _fixture = new DefaultFixture();
    public IFixture Fixture
    {
        get { return _fixture; }
        set
        {
            _fixture = value ?? new DefaultFixture();
        }
    }

    public int MatchResultId { get; set; }
    public int HomeScore { get; set; }
    public int AwayScore { get; set; }

    public bool IsDraw
    {
        get { return HomeScore == AwayScore; }
    }

    public IClub Winner
    {
        get
        {
            if (Fixture.FixtureId != DefaultFixture.DefaultId)
            {
                if (HomeScore == AwayScore)
                {
                    return new DefaultClub();
                }

                return HomeScore > AwayScore ? Fixture.HomeClub : Fixture.AwayClub;
            }

            return new DefaultClub();
        }
    }
}
Then I'd have a class for being a "Default____"
code:
public class DefaultFixture : IFixture
{
    public static int DefaultId = -1;
    public static DateTime DefaultDate = DateTime.MinValue;
    public static IClub DefaultClub = new DefaultClub();

    public int FixtureId
    {
        get { return DefaultId; }
        set { }
    }

    public DateTime Date
    {
        get { return DefaultDate; }
        set { }
    }

    public IClub HomeClub
    {
        get { return DefaultClub; }
        set { }
    }

    public IClub AwayClub
    {
        get { return DefaultClub; }
        set { }
    }
}
This is just a bit of tinkering around to see if it could be done; but I can see all of this spiralling out of control and becoming difficult to implement and test unless the project is very small. I've thought about having some sort of repository of default objects so that I can check the references instead of comparing something like FixtureId to DefaultFixture.DefaultId for example and it does just feel like I'm simply replacing null with something else that is no better.

zokie
Feb 13, 2006

Out of many, Sweden
What problem are you trying to solve exaclty? Embrace the null instead. Absolutely use nullables for keys and such. Using int? keys and the like has made my life so much easier. What you are doing just seems strange, and I really don't see any benefit to it.

Cancelbot
Nov 22, 2006

Canceling spam since 1928

I don't normally code like this, it's more an experiment to see if it is possible. But with it creating more problems than it solves I'll not be changing my approach any time soon; I was just wondering if anyone else had tried it and come up with a different way of doing it.

Dietrich
Sep 11, 2001

It's a possible and well known concept in DI called a "Null Object".

What you're doing there is basically Property Injection. While it is the (2nd) simplest form of dependency injection, Property Injection's biggest disadvantage is that it's not simple to implement it in such a way that you can always utilize that property regardless of if it has been injected or not.

If you're doing property injection with Null Object stand ins to avoid null checks, then you should make sure that your code never relies on an object returned by your null object to keep your complexity low. The last thing you want is for your NullClassA to have to return NullClassB's which return NullClassC's . If you need to dive that deeply into an object graph then you really should rely on MethodInjection or ConstructorInjection so that the requirement for the object in any given method is explicit.

zokie
Feb 13, 2006

Out of many, Sweden
How do you intend to get around casting with as? Are you going to use DefaultIfEmpty everywhere you need to use the XOrDefault LINQ-methods? And do you really plan on initializing every stinking field and property with a default value? While what you wan't to do seems possible I think that there is no sane reason for it. Especially when it comes to casting, if you don't accept using null anywhere you won't be able to cast using as, that means you need to do something like this to be safe
code:
var destination = Foo.Default);
try
{
    destination = (Foo) someBar;
}
catch { }

if(destination == Foo.Default) 
    return;

// do the needful
I took the liberty of adding the default as a static member on the type instead. Seemed like a waste to initialize a new one every time.

Before posting I realized a better way:
code:
var destination = someBar as Foo ?? Foo.Default;
Which wasn't as horrible. But still, I think this is a very strange way of doing things. Instead of accepting null, the nothing value, you replace it with a default. To me this seems like a semi-predicate problem nightmare.

Adbot
ADBOT LOVES YOU

raminasi
Jan 25, 2005

a last drink with no ice
You could always just give F# a try if you want to do null-free .NET programming :shobon:

  • Locked thread