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
Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!
What does the XML document look like when you retrieve it from the database?

Adbot
ADBOT LOVES YOU

Uziel
Jun 28, 2004

Ask me about losing 200lbs, and becoming the Viking God of W&W.
I figured it out, it was an issue with my classes and the serialization, not the retrieving of the XML. I had to make a blank public constructor in the classes when serializing and neglected to have some of the necessary properties have both get and set. :|

Uziel fucked around with this message at 18:47 on Dec 16, 2010

wwb
Aug 17, 2004

Ugh, dysgraphia strikes again -- missed the distinction between ThisDLBuilder and ThisBLBuilder. You can disregard that comment, but the error you are getting indicates there is something null or you've got a deserialization issue of some sort.

Anyhow, a few things to look at:

a) Is the Bulder object XML serializable and XML deserializable? Most unit testing frameworks have some good bits to verify this.
b) Have we confirmed that you are passing a string into the XmlDeserialize method?
b) I'd strongly consider not storing the XML in the same table -- 14k lines is an ugly, ugly load. And it could get loaded anytime you touch the builderDL object depending on ORM and settings.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

PhonyMcRingRing posted:

1. You can do the quick way and pass the same XAML string to XamlReader. http://msdn.microsoft.com/en-us/library/system.windows.markup.xamlreader.aspx

2. You can do this in code, but you're gonna write about 500% more code to get the same thing. See http://stackoverflow.com/questions/248362/how-do-i-build-a-datatemplate-in-c-code/248638#248638

If you're new to WPF, you're better off not trying to fight the way WPF wants you to handle the visual end of things. It just ends up getting messy.

Thanks for the response (and you ljw1004). I won't fight the WPF way and I'll do it in XAML. What's up with the lag in Visual Studio 2010 when you switch from a .xaml file to a .cs file? Is there anything I can do to reduce that?

edit: Moving the pane splitter so the Design tab is not visible seems to have eliminated the lag.

fletcher fucked around with this message at 20:48 on Dec 16, 2010

IcedPee
Jan 11, 2008

Yarrrr! I be here to plunder the fun outta me workplace! Avast!

FREE DECAHEDRON!
I've got this simple little context menu:

code:
<Canvas.ContextMenu>
  <ContextMenu>
    <MenuItem Header="Change Color" Name="BrushesMenu" ItemsSource="{Binding Path=Colors}">
      <MenuItem.ItemTemplate>
        <DataTemplate>
          <MenuItem Header="{Binding Path=BrushName}" Click="MenuItem_Click" />
        </DataTemplate>                        
      </MenuItem.ItemTemplate>
    </MenuItem>
    <MenuItem Header="Delete Selection" Click="DeleteMenuItem_Click" />
  </ContextMenu>
</Canvas.ContextMenu>
and it works just great until it comes time to executing MenuItem_Click. The problem is, that the menuitems that populate BrushesMenu don't stretch to fill and, as a result, the MenuItem can be selected and BrushesMenu can be selected for each item in Colors. It's pretty annoying when you (at a glance) look as though you've highlighted the menuitem you want, when in fact, you have to mouse over the text before you can actually select that menuitem. I've never had this problem with other menus, so is it just a contextmenu thing?

How do I fix it?

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

I'm trying to tackle WPF while I'm still in the c#\.net 101 phase. I feel like this is a good idea, as from what I read, wpf is THE way a user interface should be done in windows, and is only slow taking off because too many people are entrenched in the old ways and not willing to take on the learning curve.

Anyway, it is a big learning curve, especially for me. I grabbed wpf 4.0 unleashed but it moved pretty drat fast. I feel like I need a copy of baby's first wpf book. Any recommendations on learning wpf?

fankey
Aug 31, 2001

IcedPee posted:

How do I fix it?
The MenuItem.ItemTemplate is automatically placed inside a MenuItem for you - so you're ending up with a MenuItem inside a MenuItem. Try
code:
<Canvas.ContextMenu>
  <ContextMenu>
    <MenuItem Header="Change Color" Name="BrushesMenu" ItemsSource="{Binding Path=Colors}" MenuItem.Click="MenuItem_Click">
      <MenuItem.ItemTemplate>
        <DataTemplate>
          <TextBlock Text="{Binding Path=BrushName}"/>
        </DataTemplate>                        
      </MenuItem.ItemTemplate>
    </MenuItem>
    <MenuItem Header="Delete Selection" Click="DeleteMenuItem_Click" />
  </ContextMenu>
</Canvas.ContextMenu>

IcedPee
Jan 11, 2008

Yarrrr! I be here to plunder the fun outta me workplace! Avast!

FREE DECAHEDRON!
That has the proper look to it. It's made my MenuItem_Click pretty much worthless, but after some digging through e.OriginalSource in the event handler, I was able to find the data item I needed.

Thanks!

ButterChugger
Oct 12, 2007

Just a quick question i had while I'm going though my Visual Basic book here for studying before my final exam tomorrow.

I'm a bit confused on something I'm hoping that can be cleared up here. I know it's simple, but it has just gone over my head.

Why in some casses are two variables used in parathenses in an equasion just seperated by a comma? Does a comma have any reasonable use in an equasion? Here's a simple example to show what I mean because I'm sure the explaination by itself doesn't really clarify what I mean.

code:
 For intCount = 1 To intMonths
                        'Calculate the interest for this period
                        dblInterest = IPmt(dblAnnualRate / dblMONTHS_YEAR, intCount, intMonths, -dblLoan)

                        'Calculate the principal for this period.
                        dblPrincipal = PPmt(dblAnnualRate / dblMONTHS_YEAR, intCount, intMonths, -dblLoan)
And one other thing I'm not 100% sure on what is the exact use of ByVal and ByRef.

Any help at all would be greatly appreciated! Thanks :)

ButterChugger fucked around with this message at 00:26 on Dec 17, 2010

PhonyMcRingRing
Jun 6, 2002

Uziel posted:

Any ideas or advice?

Are you *actually* going to store this whole serialized object in the ViewState on a live site? If it's not an intranet-only site, you're gonna shoot yourself in the foot when the ViewState gets larger and larger. You also open up the ability for someone to edit the ViewState clientside and do god-knows-what relating to your object. You can use ViewState encryption, but I still wouldn't trust it.

fletcher posted:

edit: Moving the pane splitter so the Design tab is not visible seems to have eliminated the lag.

Yeah, making sure it only shows the xaml without the designer is usually the recommended way to go.

Sprawl
Nov 21, 2005


I'm a huge retarded sperglord who can't spell, but Starfleet Dental would still take me and I love them for it!

Aqua Hamster posted:

Just a quick question i had while I'm going though my Visual Basic book here for studying before my final exam tomorrow.

I'm a bit confused on something I'm hoping that can be cleared up here. I know it's simple, but it has just gone over my head.

Why in some casses are two variables used in parathenses in an equasion just seperated by a comma? Does a comma have any reasonable use in an equasion? Here's a simple example to show what I mean because I'm sure the explaination by itself doesn't really clarify what I mean.

code:
 For intCount = 1 To intMonths
                        'Calculate the interest for this period
                        dblInterest = IPmt(dblAnnualRate / dblMONTHS_YEAR, intCount, intMonths, -dblLoan)

                        'Calculate the principal for this period.
                        dblPrincipal = PPmt(dblAnnualRate / dblMONTHS_YEAR, intCount, intMonths, -dblLoan)
And one other thing I'm not 100% sure on what is the exact use of ByVal and ByRef.

Any help at all would be greatly appreciated! Thanks :)

That looks like your using a function/method not an equation so i'm not sure what you mean.

ButterChugger
Oct 12, 2007

Sprawl posted:

That looks like your using a function/method not an equation so i'm not sure what you mean.

Oh poo poo, my bad, that was. Either way, I'm actually still unsure what it even means with multiple variables in paranthesis. I know it's probably something incredibly simple, but it's just not registering with me.

PhonyMcRingRing
Jun 6, 2002

Aqua Hamster posted:

Any help at all would be greatly appreciated! Thanks :)

A quick google of IPmt gets me this: http://www.techonthenet.com/excel/formulas/ipmt.php

So I'm assuming that tutorial is using an Excel function.

Sprawl
Nov 21, 2005


I'm a huge retarded sperglord who can't spell, but Starfleet Dental would still take me and I love them for it!

Aqua Hamster posted:

Oh poo poo, my bad, that was. Either way, I'm actually still unsure what it even means with multiple variables in paranthesis. I know it's probably something incredibly simple, but it's just not registering with me.

When your doing math like

(1+2) * 3 = 9
1 + 2 * 3 = 7
it has to do with order of operations. If the bracket wasn't there it would go 6 + 1 because of BEDMAS ( Brackets, Exponents, Division/Multiplication, Addition/Subraction)

If that isn't what your talking about i dont know really.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Begby posted:

This is just totally shooting from the hip, but when I had permission problems logging into a report server as admin, it was because I had to log in with the local machine specific administrator account. A user with domain admin privileges would not work nor did the AD root administrator account.

Rant: This kind of poo poo is why I hate using microsoft software. Perhaps its because I just suck at using their stuff, but it seems like their software is so darn intertwined and could break spectacularly at any moment. Like the time I installed IE 8 on a test box with VS2008 and windows home.... totally broke VS. Known issue, only fix is to uninstall IE8 and never reinstall it.

Thanks for the guess, but that didn't work. The only way it does is if you're actually logged into the server and use http://localhost/reports (doesn't seem to matter who you are logged in as). This is bothersome because I'm pretty sure I know where the problem is (permissions within MSSQL Reporting Services) but I can't seem to edit anything that applies to it, or rather I do, and the interface says account x has access, but then it doesn't let anything in.

The weird thing is, I can hit that database through MSSQL Management Studio with every account I've enabled. I can even look at the Roles and Users tables inside of the ReportServer table and see all the lovely changes I've made but nothing is allowed in.

npe
Oct 15, 2004

Aqua Hamster posted:

Oh poo poo, my bad, that was. Either way, I'm actually still unsure what it even means with multiple variables in paranthesis. I know it's probably something incredibly simple, but it's just not registering with me.

It looks like the functions IPmt() and PPmt() take 4 arguments...

epswing
Nov 4, 2003

Soiled Meat
So I've got this nice little block of code to run the contents of an sql against the db (SQL Server 2008 R2 Express):

code:
using (var db = new DbDataContext())
{
	try
	{
		db.Connection.Open();
		db.Transaction = db.Connection.BeginTransaction(IsolationLevel.Serializable);
		
		using (var command = db.Connection.CreateCommand())
		{
			command.Transaction = db.Transaction;
			command.CommandText = File.ReadAllText("/path/to/file.sql");
			command.ExecuteNonQuery();
		}
		
		db.Transaction.Commit();
	}
	catch (Exception e)
	{
		db.Transaction.Rollback();
		throw e;
	}
	finally
	{
		db.Connection.Close();
	}
}
Isn't it pretty? It's all transactionified, which is a big requirement here.

Except my sql file contains naughty words like SET and IF and GO. Here's an excerpt.

code:
SET NUMERIC_ROUNDABORT OFF
GO
SET ANSI_PADDING, ANSI_WARNINGS, CONCAT_NULL_YIELDS_NULL, ARITHABORT, QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
IF EXISTS (SELECT * FROM tempdb..sysobjects WHERE id=OBJECT_ID('tempdb..#tmpErrors')) DROP TABLE #tmpErrors
GO
CREATE TABLE #tmpErrors (Error int)
GO
SET XACT_ABORT ON
GO
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
GO
BEGIN TRANSACTION
GO

PRINT N'Creating [dbo].[Plants]'
GO
CREATE TABLE [dbo].[Plants]
(
[Id] [int] NOT NULL IDENTITY(1, 1),
[AddressId] [int] NULL,
[Name] [varchar] (50) COLLATE Latin1_General_CI_AS NOT NULL
)
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating primary key [PK_Plants] on [dbo].[Plants]'
GO
ALTER TABLE [dbo].[Plants] ADD CONSTRAINT [PK_Plants] PRIMARY KEY CLUSTERED  ([Id])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating index [IX_PlantName] on [dbo].[Plants]'
GO
CREATE UNIQUE NONCLUSTERED INDEX [IX_PlantName] ON [dbo].[Plants] ([Name])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO

PRINT N'Creating [dbo].[Drivers]'
...
Actually I just realized this sql script has transactions already. Hm.

Anyways things choke on command.ExecuteNonQuery(); saying there's incorrect syntax near "GO" and "IF" and whatnot.

So.

I have an sql file, and a connection to a database, and I want to run the sql against the database in a transaction. This should be simple, right? So before I go on some codehunt for Microsoft.SqlServer.Management.Smo (I don't think I even have this dll, somehow...), do you have any suggestions/advice on how to run such a script? Do I really need to have my clients install an SMO redistributable to get this working? Alternatively do I really need to tokenize the script on "GO" (which sounds really messy)?

Update: Snagged a few dlls from the Microsoft SQL Server directory in Program Files, trying to run something like this code. Couldn't, because "Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information". So I "fixed" that by adding useLegacyV2RuntimeActivationPolicy="true" to the startup element of my app.config, now the code runs but gives me "An exception occurred while executing a Transact-SQL statement or batch." which is funny because the same sql file runs fine if I paste it into SSMS.

:negative:

epswing fucked around with this message at 17:56 on Dec 17, 2010

wwb
Aug 17, 2004

AFAIK, the only really naughty word is "GO". Or, splitting SQL on "GO" has worked very well and probably powers 65% of our automated SQL deployment stuff.

Another option, if you just need this to be command line scriptable, is a wonderful little utility called SSEutil.exe. Its a very useful little "Execute this sql script from the command line with no dependencies" little tool that also has some management features such as the ability to create and drop databases. Don't let the name fool you, the functions that work on a full blown sql server work great there too.

Zhentar
Sep 28, 2003

Brilliant Master Genius
I've got an application set up as a single instance, using WindowsFormsApplicationBase.IsSingleInstance, so that if other programs try to launch it with command line arguments, the instance that is already running can receive those arguments. I'm running into two problems with this; it takes nearly 200ms to for a new instance to start, send its parameters to the main instance, and close, so if a program runs it 20 or 30 times in a row, it takes a while to finish (even though my app doesn't need to do more than half a second of actual work). Worse, if a program does those same 20 or 30 runs in parallel instead of sequentially, some of the new instances can starve and crash ("This single-instance application could not connect to the original instance").

Is there a better way to do this?

POKEMAN SAM
Jul 8, 2004

Zhentar posted:

I've got an application set up as a single instance, using WindowsFormsApplicationBase.IsSingleInstance, so that if other programs try to launch it with command line arguments, the instance that is already running can receive those arguments. I'm running into two problems with this; it takes nearly 200ms to for a new instance to start, send its parameters to the main instance, and close, so if a program runs it 20 or 30 times in a row, it takes a while to finish (even though my app doesn't need to do more than half a second of actual work). Worse, if a program does those same 20 or 30 runs in parallel instead of sequentially, some of the new instances can starve and crash ("This single-instance application could not connect to the original instance").

Is there a better way to do this?

I don't know about passing command line arguments over from the new instance to an old one, but to just enforce single instance you can create a Mutex with the name like "MyApplication" and check its out parameter to check if you were the first one to create it. If you were, you're the first instance and you need to flag that object with GC.KeepAlive so it stays around until your application closes. If you open the mutex and you weren't the first to create it, you know there's another process floating around out there already.

lethal trash
Feb 23, 2002
You will be subjected to freezing experiments in Dachau.
I'm trying to get and set the position of a scroll bar in C#. GetScrollInfo works fine, but I'm having some trouble with SetScrollInfo, which is throwing an AccessViolationException when I call it. Here's my method signature and hows it's being called.

code:
 private static extern int SetScrollInfo(IntPtr hwnd, int fnBar, SCROLLINFO lpsi, bool fRedraw);

  public static int SetScrollPos(IntPtr hwnd, int nPos)
        {
            SCROLLINFO info = new SCROLLINFO();
            info.cbSize = (uint)Marshal.SizeOf(info);
            info.fMask = (uint)ScrollInfoMask.SIF_POS;
            info.nPos = nPos;
            try
            {
                //set the vertical scrollbar
                int result = SetScrollInfo(hwnd, (int)ScrollBarDirection.SB_VERT, info, true);
                return result;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return 0;
            }
            
        }

ScrollInfo.SetScrollPos(listView1.Handle, pos);
Anyone know what the problem could be?

gibbed
Apr 10, 2006

SCROLLINFO probably isn't marshalling properly, you probably need to add a ref there.

Sab669
Sep 24, 2009

I have now found I have an excessive amount of spare time on my hands- forced into switching to part time for school, hours getting cut at work, distance relationship with the girlfriend. So I have copious amounts of time, and I want to try and do something constructive.

I have my associate's in IT / Software, but I really don't know gently caress all. I was hardly even taught how to work with classes. Either way, I want to brush up on my C# so I can actually do stuff, but I have no idea where to start. I can't come up with a program I'd like to make, anyone have any tips on how to motivate myself? Any websites out there that have 'homework assignments' so I can try and do something?

Learning how to do stuff with graphics would be awesome, but I guess one step at a time.

Zhentar
Sep 28, 2003

Brilliant Master Genius

Ugg boots posted:

I don't know about passing command line arguments over from the new instance to an old one, but to just enforce single instance you can create a Mutex with the name like "MyApplication" and check its out parameter to check if you were the first one to create it. If you were, you're the first instance and you need to flag that object with GC.KeepAlive so it stays around until your application closes. If you open the mutex and you weren't the first to create it, you know there's another process floating around out there already.

Seemed like too much trouble to go through all that, so I just made it a No-Instance app (e.g. Main doesn't do anything) and it still takes a bit over 100ms per instance. I'm going to assume that means no .NET program will start up fast enough to satisfy me here, so I'll do something lightweight in C++ to handle this instead.

Geno
Apr 26, 2004
STUPID
DICK

Sab669 posted:

I have now found I have an excessive amount of spare time on my hands- forced into switching to part time for school, hours getting cut at work, distance relationship with the girlfriend. So I have copious amounts of time, and I want to try and do something constructive.

I have my associate's in IT / Software, but I really don't know gently caress all. I was hardly even taught how to work with classes. Either way, I want to brush up on my C# so I can actually do stuff, but I have no idea where to start. I can't come up with a program I'd like to make, anyone have any tips on how to motivate myself? Any websites out there that have 'homework assignments' so I can try and do something?

Learning how to do stuff with graphics would be awesome, but I guess one step at a time.
make an application to help use all that excessive amount of time (like outlook calendar but better)

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!

Sab669 posted:

I have now found I have an excessive amount of spare time on my hands- forced into switching to part time for school, hours getting cut at work, distance relationship with the girlfriend. So I have copious amounts of time, and I want to try and do something constructive.

I have my associate's in IT / Software, but I really don't know gently caress all. I was hardly even taught how to work with classes. Either way, I want to brush up on my C# so I can actually do stuff, but I have no idea where to start. I can't come up with a program I'd like to make, anyone have any tips on how to motivate myself? Any websites out there that have 'homework assignments' so I can try and do something?

Learning how to do stuff with graphics would be awesome, but I guess one step at a time.
this might not be for you at all but if you're into math, try Project Euler

raminasi
Jan 25, 2005

a last drink with no ice
I have an F# assembly that has as one of its dependencies the F# core assembly (naturally). Another of its assemblies is a different library that also depends on the F# core assembly. However, when I try to create an installation project, the project detects two different F# core assemblies (one with a path in the GAC somewhere and one in the Visual F# program files directory) and tries to install them both. Since they have the same name, only one of them ends up on the target machine, and then the application doesn't work because it can't find the F# core assembly.

I know I don't understand enough about the way assemblies and the GAC and all that stuff works, and now it's coming around to bite me in the rear end. How do I fix this problem?

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy

GrumpyDoctor posted:

I have an F# assembly that has as one of its dependencies the F# core assembly (naturally). Another of its assemblies is a different library that also depends on the F# core assembly. However, when I try to create an installation project, the project detects two different F# core assemblies (one with a path in the GAC somewhere and one in the Visual F# program files directory) and tries to install them both. Since they have the same name, only one of them ends up on the target machine, and then the application doesn't work because it can't find the F# core assembly.

I know I don't understand enough about the way assemblies and the GAC and all that stuff works, and now it's coming around to bite me in the rear end. How do I fix this problem?

I'll bet you're referencing two different versions of the assembly. Make sure both are targeting the same version of the .NET runtime, for starters.

raminasi
Jan 25, 2005

a last drink with no ice

Derpes Simplex posted:

I'll bet you're referencing two different versions of the assembly. Make sure both are targeting the same version of the .NET runtime, for starters.

Oh good lord why didn't I think of that :downs:

e: ok, how do I fix this? I'm not relying on any 4.0-specific code (that I know of), but I can't figure out how to get the project to "indirectly reference" 3.5 versions of assemblies instead of 4.0 versions (even when I change the targeted profile in the application tab of the project settings and remove all the references)

raminasi fucked around with this message at 03:04 on Dec 19, 2010

lethal trash
Feb 23, 2002
You will be subjected to freezing experiments in Dachau.

gibbed posted:

SCROLLINFO probably isn't marshalling properly, you probably need to add a ref there.

This worked, thanks! I found out that while this scrolls the scrollbar to a position it doesn't actually scroll the listview I'm working with. The solution was alot easier than all of the calls to unmanaged code, just set TopItem of the listview.

Nurbs
Aug 31, 2001

Three fries short of a happy meal...Whacko!
I just loaded VS2010 ultimate on a clean install of win7 and the development server is extremely slow whenever I try and run an aspx application. Every page starts off as 'Page Cannot Be Found', but if I refresh it after a minute I get the page.

Any settins I need to tweak?

ljw1004
Jan 18, 2005

rum

Nurbs posted:

I just loaded VS2010 ultimate on a clean install of win7 and the development server is extremely slow whenever I try and run an aspx application. Every page starts off as 'Page Cannot Be Found', but if I refresh it after a minute I get the page.
Any settins I need to tweak?

I saw that with IE9. When I reverted to IE8 it worked properly.

Dan7el
Dec 7, 2008

Nurbs posted:

I just loaded VS2010 ultimate on a clean install of win7 and the development server is extremely slow whenever I try and run an aspx application. Every page starts off as 'Page Cannot Be Found', but if I refresh it after a minute I get the page.

Any settins I need to tweak?

This information might be helpful:
http://stackoverflow.com/questions/2382741/slow-performance-asp-net-aspnet-wp-exe-and-csc-exe-running-after-clicking-red

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

Sab669 posted:

I have now found I have an excessive amount of spare time on my hands- forced into switching to part time for school, hours getting cut at work, distance relationship with the girlfriend. So I have copious amounts of time, and I want to try and do something constructive.

I have my associate's in IT / Software, but I really don't know gently caress all. I was hardly even taught how to work with classes. Either way, I want to brush up on my C# so I can actually do stuff, but I have no idea where to start. I can't come up with a program I'd like to make, anyone have any tips on how to motivate myself? Any websites out there that have 'homework assignments' so I can try and do something?

Learning how to do stuff with graphics would be awesome, but I guess one step at a time.

I'm still just starting out too, and this is my opinion as a beginner. Keep in mind though that I am tackling this as a pure hobby. I have no plans to ever make money programming.

Do nothing with forms(gui) at first. Keep it all console, or you'll be spinning your wheels for hours on things that will be no big deal later. I started by going through this http://www.csharp-station.com/Tutorial.aspx for the basics. Don't get caught up if something gives you trouble(delegates were murder on me). Anything that is rough on you will all make sense as soon as you NEED them to get whatever you are wanting to get done, done. From there I worked through the first 10 project euler problems, after that they got to be more about the math tricks than the programming to me. To get more in depth, I grabbed this book http://www.darelease.com/ebooks/484267-c-for-programmers-2nd-edition.html and I have been very happy with it. I also got c# in depth, but it's pretty far over my head and I would not recommend it for a beginner.

wwb
Aug 17, 2004

Crosspost, but there is some interested in a functional programming thread. Which, to a large extent means a F# thread. If anyone here feels qualified to start it up please do.

epswing
Nov 4, 2003

Soiled Meat
Another epswing wall-of-code table-breaking post. :(

I'm having a hard time putting into words what my problem is, so I'm going to paste some code and hope the point makes it across the chasm.

Here's my dbml auto-generated code:
code:
[global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.Users")]
public partial class User
{
    private int _Id;
    
    [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Id", AutoSync=AutoSync.OnInsert, 
                       DbType="Int NOT NULL IDENTITY", IsPrimaryKey=true, IsDbGenerated=true)]
    public int Id
    {
        get
        {
            return this._Id;
        }
        set
        {
            this._Id = value;
        }
    }
    
    // lots more generated code here for other columns
}
Here's a base Entity class and one subclass:

code:
public abstract class CrudEntity
{
    public abstract int Pk { get; }
}

public partial class User : CrudEntity
{
    public override int Pk { get { return Id; } }
}
Here's a base Service class and one subclass:

code:
public class CrudService<Entity> where Entity : CrudEntity, new()
{
    protected Entity GetEntity(int id)
    {
        var db = new DbDataContext();
        return db.GetTable<Entity>().SingleOrDefault<Entity>(x => x.Pk == id);
    }
    
    // other crud-like operations here
}

public class UserService : CrudService<User>
{
    // user-specific operations here
}
I want to pull crud operations out of individual services because Create/Retrieve/Update/Delete are going to be identical in most cases, which I'll override if necessary.

When I do
code:
var userService = new UserService();
var user = userService.GetEntity(42);
I get Class member CrudEntity.Pk is unmapped which is reasonable, because hey, there's no Pk column. Why have I created this Pk property? Well, the GetEntity method used to contain
code:
return db.Users.SingleOrDefault(x => x.Id == id);
when it lived in UserService. But now that I've pull GetEntity into a superclass (CrudService), and refactored User into a subclass of CrudEntity, I'd need to give CrudEntity a property like public abstract int Id { get; set; } and in the User subclass simply mark the Id property with override. But I can't, because the User class is partial with the auto-generated dbml and doesn't have override on the Id property (and why would it).

Halp!

Note 1: this guy explains the problem similarly, and fixes it with a cast, but that doesn't really work in my inheritance scenario.

Note 2: The above code is very stripped down and simplified just to get the point across, let me know if you need to see more, if I've left out anything essential.

epswing fucked around with this message at 19:52 on Dec 20, 2010

wwb
Aug 17, 2004

^^^Any reason you can't use interfaces here instead? That would dodge 95% of the issues you are having.

That and in general LINQ2SQL generated classes + extension of said class has more landmines than mozambique.

epswing
Nov 4, 2003

Soiled Meat

wwb posted:

^^^Any reason you can't use interfaces here instead? That would dodge 95% of the issues you are having.

I was going to ask how that would help me, until I realized that C# lets me specify properties in an interface. Awesome.

(The reason is I'm still infected with Java)

PhonyMcRingRing
Jun 6, 2002
Linq to Sql's attribute mapping doesn't work with inherited properties. You'd have to override the property and reimplement the ColumnAttribute on each one.

Adbot
ADBOT LOVES YOU

dwazegek
Feb 11, 2005

WE CAN USE THIS :byodood:

PhonyMcRingRing posted:

Linq to Sql's attribute mapping doesn't work with inherited properties. You'd have to override the property and reimplement the ColumnAttribute on each one.

Uhm, no you don't :confused:

It (probably) won't work on an interface, but on a abstract/virtual property it will work just fine.

  • Locked thread