locked
Object relational designer canvas RRS feed

  • Question

  • I am attempting to learn to use LINQ.  It remains to be seen whether this is going to work out for me.

    I have gone through working with Access databases with no major problems.  I am now working on SQL databases and am running into a problem already.  I am using a somewhat old text for this and the information might not get along with the versions I am running.  So here is the deal.

    I have just connected to my SQL database (I cheated and used the wizard).  Now I am being asked to create some entity classes by dragging tables to the object relational designer canvas.  The problem is, I have never seen anything that would be that and have no idea where to even look for it.

    Can anyone explain to me where I might look to find this, or perhaps what I might do instead of that?


    gwboolean

    Thursday, July 26, 2018 5:23 PM

Answers

  • OK, I finally figured most everything out.  It turns out that VB 2017 does not have the LINQ to SQL tool is not installed.  To get it you have to go back to the VS installer and get it.

    I have not yet finished setup and coding, but it looks like the template follows the instructions I have, so I will see how it all works out.


    gwboolean

    • Marked as answer by gwboolean Friday, July 27, 2018 4:58 PM
    Friday, July 27, 2018 4:04 AM

All replies

  • I'm not entirely sure, but maybe the DataSet designer is what you are looking for?  If you add a new DataSet to the project and double click it, it will open the designer and from there you can drag tables from the SQL Server Object Explorer window.

    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Thursday, July 26, 2018 6:04 PM
  • I already had set that up.  Based on the information from the text what I should end up with after setting this up, I should have a mapping .dbml file in my project.  I have used something called Entity Model, but that sets up a edmx file in my project. It looks nice, but I have no idea what the hell it does. 



    gwboolean

    Thursday, July 26, 2018 6:40 PM
  • Jumping into Entity Framework requires a solid understanding of your database is the first step. Then a different mind-set for writing EF code from conventional database coding.

    Keeping on topic of adding entities (which require a association to an actual existing table)

    In the case above we get a class for OCS_Messages with a collection for the newly added entity

    <System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")> _
    Public Overridable Property Entity1() As ICollection(Of KarenDemo)
    

    And the new entity

    Imports System.Collections.Generic
    Imports System
    
    '------------------------------------------------------------------------------
    ' <auto-generated>
    '     This code was generated from a template.
    '
    '     Manual changes to this file may cause unexpected behavior in your application.
    '     Manual changes to this file will be overwritten if the code is regenerated.
    ' </auto-generated>
    '------------------------------------------------------------------------------
    
    Namespace OcsAPI
    
    	Partial Public Class KarenDemo
    		Public Property Id() As Integer
    		Public Property SomeField() As String
    
    		Public Overridable Property OCS_MESSAGES() As OCS_MESSAGES
    	End Class
    End Namespace

    Build, get an error on mapping? Run the following then rebuild


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Thursday, July 26, 2018 7:00 PM
  • I am not even sure that is what I am supposed to be doing.  All I know is the instructions I have is telling me to create some entity classes (one for each table) that are associated with my existing table.  The method explains that I should have a Object Relational Designer Canvas and that I can drag each table into this canvas.  This canvas, when saved is supposed to be some kind of mapping file with a .dbml extension.

    The file I have now, using the Entity model is a .edmx file, which leads me to believe that this is probably not what I am supposed to be doing.

    So before I go any further into this approach, I would like to be sure that is the direction I am supposed to be going.  I am quickly beginning to believe that this LINQ is way more trouble than it is worth.


    gwboolean

    Thursday, July 26, 2018 7:09 PM
  • I already had set that up.  Based on the information from the text what I should end up with after setting this up, I should have a mapping .dbml file in my project.  I have used something called Entity Model, but that sets up a edmx file in my project. It looks nice, but I have no idea what the hell it does. 



    gwboolean

    Oh gotcha, that's Entity Framework.

    You should have something in the solution explorer that ends with .edmx, if not, you can add a new item, select the data templates, and choose ADO.NET Entity Data Model, then choose Empty EF Designer Model.  This will give you an edmx file which when double clicked will open the designer you are talking about.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Thursday, July 26, 2018 7:32 PM
  • I am not even sure that is what I am supposed to be doing.  All I know is the instructions I have is telling me to create some entity classes (one for each table) that are associated with my existing table.  The method explains that I should have a Object Relational Designer Canvas and that I can drag each table into this canvas.  This canvas, when saved is supposed to be some kind of mapping file with a .dbml extension.

    The file I have now, using the Entity model is a .edmx file, which leads me to believe that this is probably not what I am supposed to be doing.

    So before I go any further into this approach, I would like to be sure that is the direction I am supposed to be going.  I am quickly beginning to believe that this LINQ is way more trouble than it is worth.


    gwboolean

    Double click that edmx file to get to the designer you are looking for.

    And perhaps yes, it is more trouble than its worth if you are just dealing with relatively small databases and are already comfortable with the ADO style of data access.  There's lots of power and potential with EF, but it mostly begins to be a benefit with large and/or complex data sets.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Thursday, July 26, 2018 7:34 PM
  • OK, after all of that is done, I should have a console window to code and here is what is supposed to go into it:

    So I am supposed to have a CSE_DEPTDataContext(), which I do not have.  What creates that?

        Sub QueryLINQSQL()
            Dim cse_dept As New CSE_DEPTDataContext()
            Console.WriteLine("Make your selection: " & vbNewLine)
            Console.WriteLine("1. LINQ to SQL Select query")
            Console.WriteLine("2. LINQ to SQL insert query")
            Console.WriteLine("3. LINQ to SQL Update query")
            Console.WriteLine("4. LINQ to SQL Delete query")
            Dim input As String = Console.ReadLine()
            Select Case (input)
                Case "1"
                    LINQSelect(cse_dept)
                Case "2"
                Case "3"
                Case "4"
                Case "5"
            End Select
        End Sub


    gwboolean

    Thursday, July 26, 2018 8:10 PM
  • OK, I finally figured most everything out.  It turns out that VB 2017 does not have the LINQ to SQL tool is not installed.  To get it you have to go back to the VS installer and get it.

    I have not yet finished setup and coding, but it looks like the template follows the instructions I have, so I will see how it all works out.


    gwboolean

    • Marked as answer by gwboolean Friday, July 27, 2018 4:58 PM
    Friday, July 27, 2018 4:04 AM
  • One thing to keep in mind is that LINQ lets you write SQL-like queries over any object collection.  If you are working with object collections over a database, like EF provides, then you can use LINQ over a database.  But it is just as useful over any collection of objects.

    So in the end you might find that LINQ isn't all that helpful (or is too much extra work) for your particular database needs, but it could still be useful in many other places where you are working with any collection of objects.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Friday, July 27, 2018 2:43 PM
  • Thanks Reed.

    I have not given up on it yet.  I finally got the right template loaded and was able to get it all to work.  I have learned how to use it to insert, delete, update, and select to a database.  

    It does look useful, but I am still not sure I want to go this way.  Have to work with it some more before I decide.


    gwboolean

    Friday, July 27, 2018 4:58 PM