We help IT Professionals succeed at work.
Get Started

C# types or templates

858 Views
Last Modified: 2016-02-10
Can someone help me understand this code.  It is meant to be an example of how to use a C# library talking to a database called Mongo DB (http://wiki.github.com/atheken/NoRM/)

When compiling I get

Error      1      The type or namespace name 'Product' could not be found (are you missing a using directive or an assembly reference?)      ...
Error      2      The type or namespace name 'Product' could not be found (are you missing a using directive or an assembly reference?)      ...
Error      3      'Norm.ObjectId' does not contain a definition for 'NewObjectID'      ...
Error      4      The type arguments for method 'Norm.Collections.MongoCollection<Product>.FindOne<U>(U)' cannot be inferred from the usage. Try specifying the type arguments explicitly.      .....

I don't understand the syntax around the <Product> - looks like a template or something.
Assuming this looks right, where should the Product template/object be defined?

Thanks
BT
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Norm;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var db = new Mongo("test", "10.1.1.20", "27017", "");
            var coll = db.GetCollection<Product>();
            //create a new object to be added to the collection
            var obj = new Product();
            obj._id = ObjectId.NewObjectID();
            obj.Title = "Shoes";
            //save the object
            coll.Insert(obj);
            //find the object
            var obj2 = coll.FindOne(new { _id = obj._id }).First();
        }
    }
}

Open in new window

Comment
Watch Question
This problem has been solved!
Unlock 2 Answers and 3 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE