U2 Visual Studio 2013 Add-in

545 views Asked by At

I am in the same boat where I am not able to add add entities in the EDM file. I have downloaded the latest .NET Toolkit 1.3 from Rocketsoftware. Am I missing something, or the designer is still pending.

Please let me know as this will really make connecting to UniData a breeze.

Thanks.

2

There are 2 answers

0
Rajan Kumar On

You need to perform the following steps to create Entity Data Model in Visual Studio 2013.

Open Visual Studio 2013

enter image description here

Open View->Server Explorer

enter image description here

Create U2 Connection

enter image description here

enter image description here

Create C# Winform Project

enter image description here

Create ADO.NET Entity Data Model

Right click on Project and Select Add New Item.

enter image description here

On Right hand side, select “Data” and on left hand side select “ADO.NET Entity Data Model”. In the Name field , enter Customer. Select “Add” button

enter image description here

Select “EF Designer from database” and select “Next”

enter image description here

Select connection string and select “Yes” for sensitive data

enter image description here

Select Entity Framework 5.0 . Note : v2.1.1 will include Entity Framework 6.0 functionality.

enter image description here

Select all tables

enter image description here

Press Finish and you will see Entity Data Model

enter image description here

0
Rajan Kumar On

You can also use LINQ to Entity Code First Model, Visual Studio 2013 and U2 Toolkit for .NET v2.1.0.

For more information on U2 Toolkit for .NET v2.1.0, see below.

Create Single-Value Class

public class CUSTOMER
{
    public int CUSTID { get; set; }
    public string FNAME { get; set; }
    public string LNAME { get; set; }
    public virtual ICollection<CUSTOMER_ORDER> Orders { get; set; }
}

Create Multi-Value Class

public class CUSTOMER_ORDER //Syntax : FILENAME_ASSOCIATION OR FILENAME_MULTIVALUE
{
    [Column (Order =0)]
    public int CUSTID { get; set; }

    [Column(Order = 1)]
    public string PRODID { get; set; }

    [Column(Order = 2)]
    public string SER_NUM { get; set; }

    [Column(Order = 3)]
    public int Z_MV_KEY { get; set; }

    [Column(Order = 4)]
    //[ForeignKey("CUSTID")]
   public virtual CUSTOMER Customer { get; set; }

}

Create Relation between Single-Value Class and Multi-Value Class

public virtual ICollection<CUSTOMER_ORDER> Orders { get; set; }

public virtual CUSTOMER Customer { get; set; }

Create Context Class

public class CustomerContext : DbContext
{
    public CustomerContext()
    {

    }
    public DbSet<CUSTOMER> Customers { get; set; }

    public DbSet<CUSTOMER_ORDER> Orders { get; set; } //Syntax : FILENAME_ASSOCIATION OR FILENAME_MULTIVALUE

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        //modelBuilder.Conventions.Remove<IncludeMetadataConvention>();
        modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
        modelBuilder.Conventions.Remove<PluralizingEntitySetNameConvention>();
        modelBuilder.Conventions.Remove<OneToOneConstraintIntroductionConvention>();
        modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
        modelBuilder.Conventions.Remove<AssociationInverseDiscoveryConvention>();
        modelBuilder.Conventions.Remove<DatabaseGeneratedAttributeConvention>();
        modelBuilder.Conventions.Remove<DeclaredPropertyOrderingConvention>();
        modelBuilder.Conventions.Remove<RequiredNavigationPropertyAttributeConvention>();

        modelBuilder.Entity<CUSTOMER>().Property(t => t.CUSTID)
                        .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);


        Database.SetInitializer<CustomerContext>(null);
        modelBuilder.Entity<CUSTOMER>()
        .HasKey(pk => new { pk.CUSTID })
         .ToTable("CUSTOMER");

        modelBuilder.Entity<CUSTOMER_ORDER>()
            .HasKey(pk => new { pk.CUSTID, pk.Z_MV_KEY })
        .ToTable("CUSTOMER_ORDER");//Syntax : FILENAME_ASSOCIATION OR FILENAME_MULTIVALUE

        modelBuilder.Entity<CUSTOMER_ORDER>()
        .HasRequired(c => c.Customer)
        .WithMany(p => p.Orders)
        .HasForeignKey(c => c.CUSTID)
         .WillCascadeOnDelete(false);


    }
}

Add an entry in App.Config File

<add name="CustomerContext" connectionString="Database=HS.SALES;User ID=user;Password=mypass;Server=myserver;Pooling=false;ServerType=universe;PersistSecurityInfo=true;AccessMode=Native;RpcServiceType=uvcs" providerName="U2.Data.Client"/>

Run the App

static void Main(string[] args)
    {

        try
        {
            Console.WriteLine("Start...");
            Database.SetInitializer<CustomerContext>(null);
            CustomerContext ctx = new CustomerContext();
            var q = ctx.Customers.ToList();
            foreach (var item in q)
            {
                string lCUSTID = Convert.ToString(item.CUSTID);
                string lFNAME = Convert.ToString(item.FNAME); ;
                string lLNAME = Convert.ToString(item.LNAME); ;

                Console.Write("CUSTID:" + lCUSTID);
                Console.Write(" FNAME:" + lFNAME);
                Console.Write(" LNAME:" + lLNAME);

                foreach (var item2 in item.Orders)
                {
                    string lCUSTID2 = Convert.ToString(item2.CUSTID);
                    string lPRODID = Convert.ToString(item2.PRODID); ;
                    string lSER_NUM = Convert.ToString(item2.SER_NUM);
                    string lZ_MV_KEY = Convert.ToString(item2.Z_MV_KEY);

                    Console.Write("\t"+"CUSTID:" + lCUSTID2);
                    Console.Write("\t" + " PRODID:" + lPRODID);
                    Console.Write("\t" + " SER_NUM:" + lSER_NUM);
                    Console.Write("\t" + " Z_MV_KEY:" + lZ_MV_KEY);
                }


                Console.WriteLine();
            }
            Console.WriteLine("End...");
            Console.Read();

        }
        catch (Exception e)
        {
            string lErr = e.Message;
            if (e.InnerException != null)
            {
                lErr += e.InnerException.Message;
                Console.WriteLine(lErr);

            }
        }
    }

New Features in V2.1.0

  1. Complete ONE .NET Package
  2. Under one roof : SQL Access, Native Access and UniObjects API (formerly known as UO.NET)
  3. Access NoSQL (multi-value data) with SQL Syntax
  4. Populate System Builder Account Files, Attributes and Subroutines in Visual Studio Server Explorer.
  5. Multi-value ADO.NET Provider (Native Access with U2 Files, Attributes, Subroutines)
  6. Multi-Value Add-ins (U2 Files, Attributes, Subroutines in Visual Studio Server Explorer)
  7. Performance Tuning Parameters in connection string: “NativeFetch” and “UseFastGetRecordID”
  8. Automatic Data Encryption (ADE) using U2Files and Subroutines
  9. SSL using U2Files and Subroutines
  10. Connection Pooling using U2Files and Subroutines
  11. Drag and Drop U2Files and Subroutines into DataSet Designer and Entity Data Model Designer VS2010, VS2012 and VS2013 Support
  12. U2Files to JSON data ( to be used with JavaScript/HTML5, MVVM pattern/Knockout.js)
  13. ASP.NET Web API and oData support using U2Files and Subroutines ( mobile devices, Tablet App, PhoneGap Mobile App, Xamarin Mobile App, Windows Store)
  14. ASP.NET MVC4 Web Application and Classic ASP.NET Application using U2Files and Subroutines
  15. WCF using U2Files and Subroutines
  16. WPF using U2Files and Subroutines
  17. SQL Server Integration Services (SSIS) using U2Files and Subroutines
  18. SQL Server Reporting Services (SSRS) using U2Files and Subroutines
  19. SharePoint Designer and external data sources (U2 Files and Subroutines)