DaveAmour 160 Mmmmmm beer Featured Poster

Does it exist on the database server?

DaveAmour 160 Mmmmmm beer Featured Poster

It is shared because you used "static"

DaveAmour 160 Mmmmmm beer Featured Poster

The point is there are different ways to arcitect things. A simple n-tier (typically 3) was favoured for a long time but more recently a service based approach with looseley coupled services and dumb poco models is more fashionable. If you are doing this for an academic course then best to stick to what your tutors want though.

A good technique to use though, whatever architecture you are doing is an architecural spike. This is when you code a small vertical part of the app such that it touches every layer from the UI, through the business logic, the data access and the database.

This way it allows you to fine tune your layers and tinker with them until you are really happy and then coding the rest of the app is just more of the same.

DaveAmour 160 Mmmmmm beer Featured Poster

Jim is spot on "efficiency is irrellevent. Focus more on clear code" - that's exactly the mindset to be in.

Also in a real trivia game you have a Deck of used questions and a Deck of unused questions so you could model it that way maybe.

So if you have a Deck class you can then implement IEnumberable and your deck is then both a collection of questions and has other properties and methods too - eg GetNextQuestion

https://msdn.microsoft.com/en-us/library/dd145423.aspx?f=255&MSPPError=-2147217396

If you model things in this kind of way then your client or orchestration code will be clear, elegant and beautiful! Easy to understand and easy to maintain.

Finally if you have the time and desire then this is a great case for TDD http://www.codeproject.com/Articles/560137/NET-TDD-Test-Driven-Development-by-example-Part

DaveAmour 160 Mmmmmm beer Featured Poster

Vb.net is an OOP language. So model the real world and create your classes that way.

DaveAmour 160 Mmmmmm beer Featured Poster

Its a subjective decision as far as I'm aware

DaveAmour 160 Mmmmmm beer Featured Poster

Not sure if this is right but try emoving brackets:

document.getElementById('clickMe').onclick = testOne;

DaveAmour 160 Mmmmmm beer Featured Poster

You have two action attribues in your form tag - is that right?

DaveAmour 160 Mmmmmm beer Featured Poster

This can be quite a subjective topic sometimes.

Have a look at Active Record versus Repository Pattern eg:

http://stackoverflow.com/questions/6522009/active-records-vs-repository-pros-and-cons

I think Active Record is not so good anymore so go for the more decoupled design.

DaveAmour 160 Mmmmmm beer Featured Poster

In this case Contact is class. It represents a contact in my domain.

It would be a User, Person, Company, Book, Item etc

I have made the assumption you are using Entity Framework - is this in fact the case?

    public class Contact
    {
        public int Id { get; set;

        public string Firstname { get; set; }

        public string Surname { get; set; }

        public string Company { get; set; }

        public string Telephone { get; set; }

        public string Mobile { get; set; }
    }
DaveAmour 160 Mmmmmm beer Featured Poster

Load it where?

DaveAmour 160 Mmmmmm beer Featured Poster
  1. Get the current item from the database

  2. Update just the properties you want to change

  3. Use the Repository Pattern to execute code simillar to that below

        public void Update(Contact contact)
        {
            using (var context = new EfContext())
            {
                Contact existingContact = context.Contacts.Single(c => c.Id == contact.Id);
    
                context.Entry(existingContact).CurrentValues.SetValues(contact);
    
                context.SaveChanges();
            }
        }
    
DaveAmour 160 Mmmmmm beer Featured Poster

Ok nice one.

DaveAmour 160 Mmmmmm beer Featured Poster

What actually happens?

DaveAmour 160 Mmmmmm beer Featured Poster

I got my email to cash out my five dollars. I shall allow it to bounce back to you though so you can run your servers for 20 minutes longer!

tobyITguy commented: Nice guy. +0
DaveAmour 160 Mmmmmm beer Featured Poster

Thre very first reply to this post was me telling the poster to add a reference.

No need to keep repeating that, it has already been answered correctly!

DaveAmour 160 Mmmmmm beer Featured Poster

Look into the Post, Redirect Get Pattern

DaveAmour 160 Mmmmmm beer Featured Poster

DELETE FROM POS FROM [Name]=@Name - you have FROM in there twice. I think you need a WHERE as well!

DaveAmour 160 Mmmmmm beer Featured Poster

Just try it like this:

    <script>
        $(document).ready(function ($)
        {
            $('#header__icon').click(function (e)
            {
                e.preventDefault();
                $('body').toggleClass('with--sidebar');
            });

            $('#site-cache').click(function (e)
            {
                $('body').removeClass('with--sidebar');
            });
        });
    </script>
DaveAmour 160 Mmmmmm beer Featured Poster

Try this:

    <script>
        $(document).ready(function()
        {
            $('p').css("font-style", "italic");    
        });
    </script>
DaveAmour 160 Mmmmmm beer Featured Poster

Ok sure:

How do I deal with the following in a TDD way - ie write the test first then write the code to pass but in a pure TDD way - ie no integration testing:

    public class UserDb : IUserDb
    {
        public void Add(User user)
        {
            using (var context = new EfContext())
            {
                context.Users.Add(user);

                context.SaveChanges();
            }
        }
    }
DaveAmour 160 Mmmmmm beer Featured Poster

Do we have any TDD experts here? I have some questions but need an expert.

DaveAmour 160 Mmmmmm beer Featured Poster

Sure - no point in me reineventing the wheel though - here is a good video.

https://www.youtube.com/watch?v=f-hRENVTQ54

DaveAmour 160 Mmmmmm beer Featured Poster

There are various ways. BackgroundWorker is probably best.

DaveAmour 160 Mmmmmm beer Featured Poster

What is the code doing? If it is on the main thread and it is doing a lot it can freeze the UI. Consider running the code on another thread.

DaveAmour 160 Mmmmmm beer Featured Poster

Yep code would help - maybe you are just using too much memory rather than it not being garbage collected quickly enough. I'm sure that if your process needs memory and some can be garbage collected then the runtime would do so rather than crashing. If however you actually try and use more memory than you have then this would be a problem. Maybe your code can be improved to work differently or use memory in a more efficient way?

IDisposable won't help

I wrote an article on IDisposable a few years ago: http://www.paxium.co.uk/PublicArticle/Article/497

DaveAmour 160 Mmmmmm beer Featured Poster

Are you using any unmanaged resources?

DaveAmour 160 Mmmmmm beer Featured Poster

No - its only loaded when you query it.

DaveAmour 160 Mmmmmm beer Featured Poster

Open a command prompt in Windows

Type "Regsvr32" then hit enter. If it's good enough for MS, it's good enough for me!

DaveAmour 160 Mmmmmm beer Featured Poster

Ok I see.

I have never seen this before to be honest but have looked into it.

Consider the code below if I put a breakpoint on line 35. In there localContacts contains 1 item and the liveContacts contains several hundred.

So Local is all of the items which have not yet been committed to the database.

To quote MS - Gets an ObservableCollection<T> that represents a local view of all Added, Unchanged, and Modified entities in this set.

https://msdn.microsoft.com/en-us/library/gg696248%28v=vs.113%29.aspx?f=255&MSPPError=-2147217396

EFLocal.png

DaveAmour 160 Mmmmmm beer Featured Poster

Ok I shall quote you on that next time you are online and I stalk, I mean chat with you!

DaveAmour 160 Mmmmmm beer Featured Poster

In your code above is line 2 being run multiple times? Are you wiring the even handler up again and again somehow? Difficult to say without seein the whole thing in context but that's what it sounds like to me.

DaveAmour 160 Mmmmmm beer Featured Poster

Isn't that a bit stalky?

DaveAmour 160 Mmmmmm beer Featured Poster

I like chatting to people but no one is ever there :(

DaveAmour 160 Mmmmmm beer Featured Poster

Try

if (conn.State != ConnectionState.Open)
{
    conn.Open();              
}

sql.ExecuteNonQuery();
DaveAmour 160 Mmmmmm beer Featured Poster

MrM - The code was just for pritaeas to show that you can use a message box in a console app - the language is not important.

I have already given the correct answer to this question which is to add a reference.

DaveAmour 160 Mmmmmm beer Featured Poster
using System.Windows.Forms;

namespace FormsTest
{
    class Program
    {
        static void Main(string[] args)
        {
            MessageBox.Show("I am a WinForms Message Box in a Console App");
        }
    }
}
DaveAmour 160 Mmmmmm beer Featured Poster
DaveAmour 160 Mmmmmm beer Featured Poster

It means it could be unassigned. What if someone entered 4?

Try:

            switch (classChoice)
            {
                case 1:
                    classChosen = "Fighter";
                    break;
                case 2:
                    classChosen = "Priest";
                    break;
                case 3:
                    classChosen = "Wizard";
                    break;
                default:
                    classChosen = "Unknown";
                    break;
            }
DaveAmour 160 Mmmmmm beer Featured Poster

I have that too.

DaveAmour 160 Mmmmmm beer Featured Poster

I noticed this too on my 27" monitor!

It looks fine, I'm just so used to seeing it how it was before that it just takes some getting used to.

DaveAmour 160 Mmmmmm beer Featured Poster

In that tutorial there is the following - does that help?

Where’s My Data?

By convention DbContext has created a database for you.
If a local SQL Express instance is available (installed by default with Visual Studio 2010) then Code First has created the database on that instance
If SQL Express isn’t available then Code First will try and use LocalDb (installed by default with Visual Studio 2012)

There is a link in there too on the actual page telling you about LocalDb.

DaveAmour 160 Mmmmmm beer Featured Poster

Ive not seen **Local** before.

Does that actually work??

DaveAmour 160 Mmmmmm beer Featured Poster

Sory can't really help much then I'm afraid.

DaveAmour 160 Mmmmmm beer Featured Poster

Is this online anywhere so I can see it?

DaveAmour 160 Mmmmmm beer Featured Poster

@Slavi - There is a famous chess opening called the Slav

Slavi commented: great! :D Pretty big chess fan myself =] +6
DaveAmour 160 Mmmmmm beer Featured Poster

Just thought - are you talking bout manually creating an empty database and then using code first? In that case yes then code first is not actually creating the database as such, it is creating the database tables etc.

The connection string, which is almost certainly in a .config file is the easiest place to find the database though in my oppinion. I also suspect that the OP didn't create the database manually otherwise they would know where it is I would hope!

DaveAmour 160 Mmmmmm beer Featured Poster

Sorry I'm confused. If a code first approach doesn't generate your database from your models then where does the database come from?

DaveAmour 160 Mmmmmm beer Featured Poster

deceptikon - he says hes doing codefirst so the code will generate the database - where it does that depends on the connection string.

DaveAmour 160 Mmmmmm beer Featured Poster

Do you have a connection string?