Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Craig P 13 posts 94 karma points
    Jun 03, 2021 @ 12:36
    Craig P
    0

    Accessing External database from a view - help!

    Hi,

    I have a product page where most of the data comes from a CMS but some technical specs for that product comes from an external SQL database. I have been trying to work out how to do this and found this on the forum:

    https://our.umbraco.com/forum/developers/razor/49750-Accessing-external-database-from-partial-view-macro-

    This basically is a simple POCO query which would be perfect, however, it states in the forum post that you need to create a model for the table structure, which is fine and I have done that, put it in the models folder and adding the namespace at the top and the code can't find it (it is the actual using statement which errors)

    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: CS0246: The type or namespace name 'Product' could not be found (are you missing a using directive or an assembly reference?)

    Source Error:

    Line 1: @using Product.Models;

    The model is:

    namespace Product.Models  {
    
    public class SKUList{
    
    public int ID { get; set; }
    public string PartNumber { get; set; }
    public string Tech1 { get; set; }
    public string Tech2 { get; set; }
    
    
    }
    }
    

    Can someone please give me an idea of how I create this model and link it so that the code will work? Its one simple query I am needed, to display three variables from the external database on the screen.

    Can anybody point me in the right direction here, hopefully, I'm doing something silly?

    Thanks.

  • Marc Goodson 2142 posts 14345 karma points MVP 8x c-trib
    Jun 03, 2021 @ 19:56
    Marc Goodson
    0

    Hi Craig

    Are you using Visual Studio to work locally with your project?

    And do you have anything else called 'Product' in your solution...

    If you call your namespace something more unique eg

    namespace CraigP.Product.Models  {
    

    that would rule out any clashes with anything else called Product...

    But the Model still needs to be compiled, so if you are not using Visual Studio to compile the project code, then try creating a folder called app_code in your project and move your model class into that folder, and then it should 'compile on the fly'...

    regards

    Marc

Please Sign in or register to post replies

Write your reply to:

Draft