Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to Reflection on EntityFramework Classes (model first approach)?
    primarykey
    data
    text
    <p>It's possible to create instance of classes generated for VisualStudio when use DataBase First ?</p> <p>I mean, I use the t4 templates and the command "Generate Code" using T4 templates for MVC3 Tools Update to create my classes from db with a many to many relationship.</p> <p>Can I Use reflection to "populate" the properties of an instance for example of "Student" of this classes in a distinct assembly (dll) ?</p> <p>For example with 3 tables: "courses" "students" "studentsCourses"</p> <p>I will have 3 entities, on for courses, one for students and one for the relationship. Can I receive an object or type "student" and use reflection to "populate" all it's properties ? and If yes, how can I achieve this ?</p> <p>I already know I can receive the object by reference as "object type" (using generics) but I just can't figure out how to create/fill the complex properties (for example in the studentsCourses property)</p> <p>Any advice thanks in advance.</p> <p>Here I let the script to create the tables and the database "COURSES_TEST":</p> <pre><code>USE [master] GO /****** Object: Database [COURSES_TEST] Script Date: 04/12/2013 23:47:18 ******/ CREATE DATABASE [COURSES_TEST] ON PRIMARY ( NAME = N'COURSES_TEST', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\COURSES_TEST.mdf' , SIZE = 2048KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB ) LOG ON ( NAME = N'COURSES_TEST_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\COURSES_TEST_log.ldf' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%) GO ALTER DATABASE [COURSES_TEST] SET COMPATIBILITY_LEVEL = 100 GO IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled')) begin EXEC [COURSES_TEST].[dbo].[sp_fulltext_database] @action = 'enable' end GO ALTER DATABASE [COURSES_TEST] SET ANSI_NULL_DEFAULT OFF GO ALTER DATABASE [COURSES_TEST] SET ANSI_NULLS OFF GO ALTER DATABASE [COURSES_TEST] SET ANSI_PADDING OFF GO ALTER DATABASE [COURSES_TEST] SET ANSI_WARNINGS OFF GO ALTER DATABASE [COURSES_TEST] SET ARITHABORT OFF GO ALTER DATABASE [COURSES_TEST] SET AUTO_CLOSE OFF GO ALTER DATABASE [COURSES_TEST] SET AUTO_CREATE_STATISTICS ON GO ALTER DATABASE [COURSES_TEST] SET AUTO_SHRINK OFF GO ALTER DATABASE [COURSES_TEST] SET AUTO_UPDATE_STATISTICS ON GO ALTER DATABASE [COURSES_TEST] SET CURSOR_CLOSE_ON_COMMIT OFF GO ALTER DATABASE [COURSES_TEST] SET CURSOR_DEFAULT GLOBAL GO ALTER DATABASE [COURSES_TEST] SET CONCAT_NULL_YIELDS_NULL OFF GO ALTER DATABASE [COURSES_TEST] SET NUMERIC_ROUNDABORT OFF GO ALTER DATABASE [COURSES_TEST] SET QUOTED_IDENTIFIER OFF GO ALTER DATABASE [COURSES_TEST] SET RECURSIVE_TRIGGERS OFF GO ALTER DATABASE [COURSES_TEST] SET DISABLE_BROKER GO ALTER DATABASE [COURSES_TEST] SET AUTO_UPDATE_STATISTICS_ASYNC OFF GO ALTER DATABASE [COURSES_TEST] SET DATE_CORRELATION_OPTIMIZATION OFF GO ALTER DATABASE [COURSES_TEST] SET TRUSTWORTHY OFF GO ALTER DATABASE [COURSES_TEST] SET ALLOW_SNAPSHOT_ISOLATION OFF GO ALTER DATABASE [COURSES_TEST] SET PARAMETERIZATION SIMPLE GO ALTER DATABASE [COURSES_TEST] SET READ_COMMITTED_SNAPSHOT OFF GO ALTER DATABASE [COURSES_TEST] SET HONOR_BROKER_PRIORITY OFF GO ALTER DATABASE [COURSES_TEST] SET READ_WRITE GO ALTER DATABASE [COURSES_TEST] SET RECOVERY SIMPLE GO ALTER DATABASE [COURSES_TEST] SET MULTI_USER GO ALTER DATABASE [COURSES_TEST] SET PAGE_VERIFY CHECKSUM GO ALTER DATABASE [COURSES_TEST] SET DB_CHAINING OFF GO USE [COURSES_TEST] GO /****** Object: Table [dbo].[students] Script Date: 04/12/2013 23:47:19 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[students]( [studentID] [int] IDENTITY(1,1) NOT NULL, [name] [nvarchar](50) NULL, [lastName] [nvarchar](50) NULL, CONSTRAINT [PK_students] PRIMARY KEY CLUSTERED ( [studentID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: Table [dbo].[courses] Script Date: 04/12/2013 23:47:19 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[courses]( [courseID] [int] IDENTITY(1,1) NOT NULL, [course] [nchar](10) NULL, [description] [nvarchar](50) NULL, CONSTRAINT [PK_courses] PRIMARY KEY CLUSTERED ( [courseID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: Table [dbo].[Studentscourses] Script Date: 04/12/2013 23:47:19 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[Studentscourses]( [courseStudentID] [int] IDENTITY(1,1) NOT NULL, [courseID] [int] NULL, [studentID] [int] NULL, CONSTRAINT [PK_Studentscourses] PRIMARY KEY CLUSTERED ( [courseStudentID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: ForeignKey [FK_Studentscourses_courses] Script Date: 04/12/2013 23:47:19 ******/ ALTER TABLE [dbo].[Studentscourses] WITH CHECK ADD CONSTRAINT [FK_Studentscourses_courses] FOREIGN KEY([courseID]) REFERENCES [dbo].[courses] ([courseID]) GO ALTER TABLE [dbo].[Studentscourses] CHECK CONSTRAINT [FK_Studentscourses_courses] GO /****** Object: ForeignKey [FK_Studentscourses_students] Script Date: 04/12/2013 23:47:19 ******/ ALTER TABLE [dbo].[Studentscourses] WITH CHECK ADD CONSTRAINT [FK_Studentscourses_students] FOREIGN KEY([studentID]) REFERENCES [dbo].[students] ([studentID]) GO ALTER TABLE [dbo].[Studentscourses] CHECK CONSTRAINT [FK_Studentscourses_students] GO </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload