DaveAmour 160 Mmmmmm beer Featured Poster

You can set this in your web.config eg:

  <system.web>
    <customErrors mode="Off" ></customErrors>
    <compilation debug="true" targetFramework="4.5" ></compilation>
    <httpRuntime targetFramework="4.5" ></httpRuntime>
    <authentication mode="Forms">
      <forms loginUrl="~/Account/Login" timeout="2880" ></forms>
    </authentication>
    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" ></add>
        <add namespace="System.Web.Mvc" ></add>
        <add namespace="System.Web.Mvc.Ajax" ></add>
        <add namespace="System.Web.Mvc.Html" ></add>
        <add namespace="System.Web.Optimization" ></add>
        <add namespace="System.Web.Routing" ></add>
        <add namespace="System.Web.WebPages" ></add>
      </namespaces>
    </pages>
  </system.web>
DaveAmour 160 Mmmmmm beer Featured Poster

Should $ITEM be inside the speech marks?

DaveAmour 160 Mmmmmm beer Featured Poster

You're welcome.

DaveAmour 160 Mmmmmm beer Featured Poster
Performing Selective Includes in Entity Framework with the Fluent API

When we are using Entity Framework as our data access choice to work with SQL Server then there are some potential pitfalls.

One of these pitfalls is doing selective includes. What do I mean by selective includes?

To answer that let's first look at our class and database model.

Lets suppose we have some customers and some invoices in our application. Our database schema and model classes could look like this:

schema.png

And we may have data like this:

data.png

Now suppose we wanted to select all customer records and their invoices raised in August 2014. With plain SQL we might do something like this:

select-invoices.png

And from there we could create one customer object in C# for Mary and load in 3 invoice objects into her Invoices collection. Nice and simple.

In Entity Framework our first go at coding this problem might look something like this:

GetCustomerAndInvoicesByDateRange.png

If we run this and debug it though we see that all invoices have been loaded as seen below:

Debug1.png

The reason for this is that our code in plain English is actually saying get Customers where they have any invoices in August 2014 and include invoices.

Entity Framework will actually include all of the Invoices though - the where clause is just acting on customers - ie select customers who have …

DaveAmour 160 Mmmmmm beer Featured Poster

Hi Michael

DaveAmour 160 Mmmmmm beer Featured Poster

Ok thanks, I shall check tomorrow.

Meanwhile do excuse my sarcasm, it increases proportionatley with age, I do like your site very much though!

DaveAmour 160 Mmmmmm beer Featured Poster

Also it also seems FF doesn't like "scroll" - try renaming your function to something else.

DaveAmour 160 Mmmmmm beer Featured Poster

Actually it might be that you closed your a tag twice.

Remove the / at the end of the first part of the a tag.

DaveAmour 160 Mmmmmm beer Featured Poster

Works for me: https://jsfiddle.net/xyt0527j/

FF Version 33.1.1

DaveAmour 160 Mmmmmm beer Featured Poster

Ok thanks Dani, awaiting email with excitement!

DaveAmour 160 Mmmmmm beer Featured Poster

I finally saw a paypal button on my $Rewards.

Perhaps rather optimistically I clicked on it.

The page then changed to show the following:

"Last Cash Out: Pending for $5.58"

Any ideas anyone.

DaveAmour 160 Mmmmmm beer Featured Poster

I keep all my stuff in source control that way its always backed up in the cloud - a good habit to get into.

DaveAmour 160 Mmmmmm beer Featured Poster

Have you actually used your IsNumeric function?

DaveAmour 160 Mmmmmm beer Featured Poster

Here's my go:

    <script>
        function CustomDate()
        {
            this.date = new Date();  
            this.dayPart = this.date.getHours() < 12 ? "AM" : "PM";

            this.toString = function()
            {
                return this.date.getMonth() + "/" + this.date.getDate() + "/" + this.date.getFullYear()
                    + " - " + this.date.getHours( ) + ":" + this.date.getMinutes()
                    + ":" + this.date.getSeconds() + " " + this.dayPart;
            };
        }

        var d = new CustomDate();

        alert(d);
    </script>
DaveAmour 160 Mmmmmm beer Featured Poster

Not sure if this is what you mean or not but try setting the following on topwrapper div:

position: fixed;
top: 1px;
background-color: #414141

Does that help?

DaveAmour 160 Mmmmmm beer Featured Poster

Hi

I'm not a Java Programmer so can't comment on the specifics of your code. However, you should not have any UI code in such a class as it is then tightly coupled to that particular UI.

UI operations should be done outside of this class and you should interact with instances of this class to set and read data.

DaveAmour 160 Mmmmmm beer Featured Poster

Can you be a little more specific.

For example have you already

a) Created a MVC project?
b) Created a Controller?
c) Created a Controller Action?
d) Created a View

And so on...

DaveAmour 160 Mmmmmm beer Featured Poster

What do you mean by manually?

DaveAmour 160 Mmmmmm beer Featured Poster

Finally had a good chance to look at your earlier post which ypo commented as:

"Troy, I may be wrong, but I think Dave was only trying to wrap all of Cat's code inside the Cat function.

And there's a way of doing something similar to it:"

I like your code as it is well encapsulated, thanks!

DaveAmour 160 Mmmmmm beer Featured Poster

Thanks AleMonteiro, that's very useful.

DaveAmour 160 Mmmmmm beer Featured Poster

Youre welcome, any exucse to play around with Linq!

DaveAmour 160 Mmmmmm beer Featured Poster

Just realised that if I add some properties then I am getting the state of my object output. See codebelow. It is not telling me anything about fucntions or prototypes thouhg. Is this what you would expect?

<script>
    function Animal(name, age)
    {
        this.breathe = function ()
        {
            alert("I am breathing");
        };

        this.eat = function ()
        {
            alert("I am eating");
        };

        this.sleep = function ()
        {
            alert("I am sleeping");
        };

        this.name = name;
        this.age = age;
    }

    var _log = function (label, obj)
    {
        if (typeof console.log === 'function')
        {
            console.log(label + ": " + JSON.stringify(obj, undefined, '\t'));
        }

        document.write(label + ": " + JSON.stringify(obj, undefined, '\t'));
    };

    var cat = new Animal("Joey", 14);

    _log("Animal", cat);

</script>
DaveAmour 160 Mmmmmm beer Featured Poster

I was trying your _log function.

Do I need to include a JSON library for this?

When I put your code in a page with nothing else, I see there is a JSON object there with a stringify function.

I just get an empty object logged though.

Can you explain please?

Thanks

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
    <script>
        function Animal()
        {
            this.breathe = function ()
            {
                alert("I am breathing");
            };

            this.eat = function ()
            {
                alert("I am eating");
            };

            this.sleep = function ()
            {
                alert("I am sleeping");
            };
        }

        var _log = function (label, obj)
        {
            if (typeof console.log === 'function')
            {
                console.log(label + ": " + JSON.stringify(obj, undefined, '\t'));
            }
        };

        var cat = new Animal();

        _log("Animal", cat);

    </script>
</body>
</html>
DaveAmour 160 Mmmmmm beer Featured Poster

Yes I know all about the chimps thanks!

DaveAmour 160 Mmmmmm beer Featured Poster

Hi

Sorry for the late replay, out all day yesterday.

The compact shorthand I have used here is called a Method Group.

To really understand this I would type for about 10 pages or if you have time watch these videos in this order. Will take a while but they are really high quality and very enjoyable.

https://www.youtube.com/watch?v=v6Zb0nD7PHA&index=1&list=PLdbkZkVDyKZVvizO94tJNmTfRzXWGDFZ3

https://www.youtube.com/watch?v=0nd-tcQcslc&list=PLdbkZkVDyKZVvizO94tJNmTfRzXWGDFZ3&index=2

https://www.youtube.com/watch?v=0qnwc5XqVs0&list=PLdbkZkVDyKZVvizO94tJNmTfRzXWGDFZ3&index=3

https://www.youtube.com/watch?v=WJItr-ecdCE

https://www.youtube.com/watch?v=OqSXsmAAZcw

Finally consider the following progression - think of that image of an ape gradually evolving into a human!

//var lettersOnly = String.Join("", word.ToLower().Where(delegate(char c) { return Char.IsLetter(c); }));
//var lettersOnly = String.Join("", word.ToLower().Where((char c) => { return Char.IsLetter(c); }));
//var lettersOnly = String.Join("", word.ToLower().Where(c => { return Char.IsLetter(c); }));
//var lettersOnly = String.Join("", word.ToLower().Where(c => Char.IsLetter(c)));
var lettersOnly = String.Join("", word.ToLower().Where(Char.IsLetter));
ddanbe commented: Gee man, again great stuff! +15
DaveAmour 160 Mmmmmm beer Featured Poster

How about this:

using System;
using System.Linq;

namespace Palindrome
{
    public class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("racecar: " + "racecar".IsPalindrome());
            Console.WriteLine("dad: " + "dad".IsPalindrome());
            Console.WriteLine("mum: " + "mum".IsPalindrome());
            Console.WriteLine("dog: " + "dog".IsPalindrome());
            Console.WriteLine("floor: " + "floor".IsPalindrome());
            Console.WriteLine("Racecar: " + "Racecar".IsPalindrome());
            Console.WriteLine("Rac ecar: " + "Rac ecar".IsPalindrome());
            Console.WriteLine("Racecar': " + "Racecar'".IsPalindrome());

            Console.ReadKey();
        }
    }

    public static class StringExtensions
    {
        public static bool IsPalindrome(this string word)
        {
            var lettersOnly = String.Join("", word.ToLower().Where(Char.IsLetter));

            var reversedWord = String.Join("", lettersOnly.Reverse());

            return lettersOnly == reversedWord;        
        }
    }
}
ddanbe commented: Great LINQ! +15
DaveAmour 160 Mmmmmm beer Featured Poster

Just managed to have a quick play around. Off to work in a mo though.

I realise that one of my problems is that when I am tinkering with code and trying out different ides I like to inspect my objects to see what has actually happened. For this I use a combination of Visual Studio and browser consoles/developer tools.

These all seem to give different results thouhg - look at the screen dumps I collected all looking at the same web page and object. How do you guys cope with this? What do you use for the truth about an object?

Browsers.png

DaveAmour 160 Mmmmmm beer Featured Poster

Another easy performance improvement with your current code - use a paralyzed foreach. These can add a lot of performance very easily.

DaveAmour 160 Mmmmmm beer Featured Poster

Hi guys

I haven't forgot about this thread. I am busy the next 2 days but will have a good play around with your ideas on Sunday.

Thanks to everyone who has understood my original question and posted useful and constructive comments, much appreciated.

DaveAmour 160 Mmmmmm beer Featured Poster

I haven't done this for a long time but used to use something called Index Server. This indexed certain folders which you specified and you queried index server much like you query a database - this was mainly for searching file contents I think.

You can certainly see what kind of simillar technologies are available these days. Depends if you are searching file names/types only or contents as well.

Also how often do your folder contents change? If not too often then caching is a defination consideration.

Also are you searching just in file names or contents as well?

If just the former you could cache the whole thing in memory and even cache search results in memory too so if person a searches the same as person b did 10 minutes ago then the results are there in memory already.

Hope that helps.

DaveAmour 160 Mmmmmm beer Featured Poster

If you are iterating over a collection which has enumerable properties then you can use foreach. For example:

foreach (var customer in customers)
{
    Console.WriteLine(customer.FirstName + " " + customer.LastName);
}

You could also achieve the same with a for loop:

for (var i = 0; i < customers.Count; i ++)
{
    Console.WriteLine(customers[i].FirstName + " " + customers[i].LastName);
}

In this case the first is more readable and easier to code right?

If you want to do a loop for some other reason though such as not iterating over a collectio but doing something x times then maybe a for loop is better. Also a for loop gives you access to the number of iterations you are on. So if you want to output:

1 Dave Amour
2 Fred Bloggs
3 Sarah Smith

Then there may be a case for using a for loop - it's up to you to make that call though.

Note - in order to be able to use foreach then the collection you are iterating over must implement IEnumberable or IEumerable<T>. Almost all collections do.

Here is a console app you can tinker with.

using System;
using System.Collections.Generic;

namespace ForeachVerusForLoop
{
    class Program
    {
        static void Main(string[] args)
        {
            var customers = GetCustomers();

            foreach (var customer in customers)
            {
                Console.WriteLine(customer.FirstName + " " + customer.LastName);
            }

            for (var i = 0; i < customers.Count; i ++)
            {
                Console.WriteLine(customers[i].FirstName + " " + customers[i].LastName);
            }

            Console.ReadKey();
        }

        static List<Customer> …
DaveAmour 160 Mmmmmm beer Featured Poster

I think web.archive.org doesn't work as well as it used to.

Are there any alternatives to that?

DaveAmour 160 Mmmmmm beer Featured Poster

Don't know if this is any help but this works for me.

Connection string is:

<add name="OracleConnection" connectionString="User Id=MyUserId; password=MyPassword; Data Source=MyServer:1521/orcl.MyUrl.co.uk; Pooling=false;"/>

And code is:

        private static IEnumerable<Document> GetDocuments(string selectText)
        {
            var documents = new List<Document>();

            using (var oracleConnection = new Oracle.ManagedDataAccess.Client.OracleConnection(ApplicationConfiguration.ConnectionString))
            {
                using (var oracleCommand = new Oracle.ManagedDataAccess.Client.OracleCommand(selectText))
                {
                    oracleCommand.CommandType = CommandType.Text;

                    oracleCommand.Connection = oracleConnection;

                    oracleConnection.Open();

                    using (var reader = oracleCommand.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var doc = new Document
                                {
                                    DocId = reader.GetInt32(0),
                                    DocumentType = (DocumentType) Enum.Parse(typeof (DocumentType), reader.GetString(1)),
                                    DateStored = reader.GetDateTime(2),
                                    ImageBlob = (MemoryStream) reader.GetStream(3)
                                };

                            documents.Add(doc);
                        }
                    }
                }
            }

            return documents;
        }
DaveAmour 160 Mmmmmm beer Featured Poster

The question is really about if statements and counters.

We could be counting bananas instead.

The questions of whether zero is positive or negative or neither has already been dealt with by mathematicians.

DaveAmour 160 Mmmmmm beer Featured Poster

Thanks Dani

DaveAmour 160 Mmmmmm beer Featured Poster

Whether zero is positive, negative or neither is outside the scope of this question.

DaveAmour 160 Mmmmmm beer Featured Poster

You can also do thing like this:

Delete From Agents

Where Id = 2

And (Select Count(*) From Agents) > 1
DaveAmour 160 Mmmmmm beer Featured Poster

I accidentally clicked on:

Click here to no longer receive any community emails from DaniWeb.

In an email I received.

How can I undo this?

Is it the checkbox in edit profile - Receive Occasional Community-related Email?

Thanks

DaveAmour 160 Mmmmmm beer Featured Poster

Delete Line 30, 31 and 33

Move Line 32 to after your loop

Change "else if ( Number <0)" to "else" - no need to check as it must be less than 0

DaveAmour 160 Mmmmmm beer Featured Poster

I'm really sorry but your sentence doesn't make much sense.

Try writing it in your native langauge and then running it through google translate maybe?

DaveAmour 160 Mmmmmm beer Featured Poster
DaveAmour 160 Mmmmmm beer Featured Poster

What does it return then?

Is it working or Erroring?

DaveAmour 160 Mmmmmm beer Featured Poster

In what way is it not working?

DaveAmour 160 Mmmmmm beer Featured Poster

That already is ajax. Can you be more specific?

DaveAmour 160 Mmmmmm beer Featured Poster

Sorry I still don't understand.

DaveAmour 160 Mmmmmm beer Featured Poster

I think to do this you need to do a cartesian join with the table on itself and implement the where condition.

DaveAmour 160 Mmmmmm beer Featured Poster

Sorry I don't understand what you are asking :(

DaveAmour 160 Mmmmmm beer Featured Poster

Ok so what's the actual problem?

DaveAmour 160 Mmmmmm beer Featured Poster

You can call a function from anywhere.

You can call a function from main and this function inside it's body can call other functions. Those other functions can also call functions. This is how you build up complex applications.

A recursive function is one that calls itself. This is often used for things like traversing a directory structure or things of that nature.

There are many good tutorials on this.

Check out the following for example.

http://www.zentut.com/c-tutorial/c-recursive-function/
http://www.programiz.com/c-programming/c-recursion
http://www.cprogramming.com/tutorial/lesson16.html

Hope that helps.

DaveAmour 160 Mmmmmm beer Featured Poster

Hi TekknoDraykko

I wasn't really suggesting the use of Nuget in the way you think. I was just asking if Suzie used it to load other 3rd party libraries.

However you can use Nuget to load components from your own private repository. This would probably most useful in a corporate environment.

There are articles out there already so no point in me re-inventing the wheel.

This looks like a good article:

https://docs.nuget.org/create/hosting-your-own-nuget-feeds