Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8131039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:57:11+00:00 2026-06-06T08:57:11+00:00

I am a beginner and have just started experimenting with the modeling tool in

  • 0

I am a beginner and have just started experimenting with the modeling tool in Entity Framework 4.1.

The picture shows a diagram of my database and further down there are the automatically generated scripts to create my database (SQL Server 2008).

enter image description here

-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 06/25/2012 21:49:52
-- Generated from EDMX file: D:\Libraries\Documents\Visual Studio 2010\HomeControl\DAL\HomeControlModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [HomeControl];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_CameraImage]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ImageSet] DROP CONSTRAINT [FK_CameraImage];
GO
IF OBJECT_ID(N'[dbo].[FK_EventTypeAction]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ActionSet] DROP CONSTRAINT [FK_EventTypeAction];
GO
IF OBJECT_ID(N'[dbo].[FK_UnitAction]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ActionSet] DROP CONSTRAINT [FK_UnitAction];
GO
IF OBJECT_ID(N'[dbo].[FK_UserAction]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ActionSet] DROP CONSTRAINT [FK_UserAction];
GO
IF OBJECT_ID(N'[dbo].[FK_ScheduleUser]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserSet] DROP CONSTRAINT [FK_ScheduleUser];
GO
IF OBJECT_ID(N'[dbo].[FK_UnitCommand]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CommandSet] DROP CONSTRAINT [FK_UnitCommand];
GO
IF OBJECT_ID(N'[dbo].[FK_Camera_inherits_Unit]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UnitSet_Camera] DROP CONSTRAINT [FK_Camera_inherits_Unit];
GO
IF OBJECT_ID(N'[dbo].[FK_Tellstick_inherits_Unit]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UnitSet_Tellstick] DROP CONSTRAINT [FK_Tellstick_inherits_Unit];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[UserSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserSet];
GO
IF OBJECT_ID(N'[dbo].[ActionTypeSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ActionTypeSet];
GO
IF OBJECT_ID(N'[dbo].[UnitSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UnitSet];
GO
IF OBJECT_ID(N'[dbo].[ImageSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ImageSet];
GO
IF OBJECT_ID(N'[dbo].[ScheduleSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ScheduleSet];
GO
IF OBJECT_ID(N'[dbo].[ActionSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ActionSet];
GO
IF OBJECT_ID(N'[dbo].[CommandSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CommandSet];
GO
IF OBJECT_ID(N'[dbo].[UnitSet_Camera]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UnitSet_Camera];
GO
IF OBJECT_ID(N'[dbo].[UnitSet_Tellstick]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UnitSet_Tellstick];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'UserSet'
CREATE TABLE [dbo].[UserSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Schedule_Id] int  NOT NULL
);
GO

-- Creating table 'ActionTypeSet'
CREATE TABLE [dbo].[ActionTypeSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'UnitSet'
CREATE TABLE [dbo].[UnitSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'ImageSet'
CREATE TABLE [dbo].[ImageSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Description] nvarchar(max)  NULL,
    [Data] varbinary(max)  NOT NULL,
    [Camera_Id] int  NOT NULL
);
GO

-- Creating table 'ScheduleSet'
CREATE TABLE [dbo].[ScheduleSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [OneOff] datetime  NULL,
    [Cronexpression] nvarchar(max)  NULL
);
GO

-- Creating table 'ActionSet'
CREATE TABLE [dbo].[ActionSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Time] datetime  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [EventType_Id] int  NOT NULL,
    [Unit_Id] int  NOT NULL,
    [User_Id] int  NOT NULL
);
GO

-- Creating table 'CommandSet'
CREATE TABLE [dbo].[CommandSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [Unit_Id] int  NOT NULL
);
GO

-- Creating table 'UnitSet_Camera'
CREATE TABLE [dbo].[UnitSet_Camera] (
    [Login] nvarchar(max)  NOT NULL,
    [Password] nvarchar(max)  NOT NULL,
    [URL] nvarchar(max)  NOT NULL,
    [Id] int  NOT NULL
);
GO

-- Creating table 'UnitSet_Tellstick'
CREATE TABLE [dbo].[UnitSet_Tellstick] (
    [Id] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'UserSet'
ALTER TABLE [dbo].[UserSet]
ADD CONSTRAINT [PK_UserSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ActionTypeSet'
ALTER TABLE [dbo].[ActionTypeSet]
ADD CONSTRAINT [PK_ActionTypeSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'UnitSet'
ALTER TABLE [dbo].[UnitSet]
ADD CONSTRAINT [PK_UnitSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ImageSet'
ALTER TABLE [dbo].[ImageSet]
ADD CONSTRAINT [PK_ImageSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ScheduleSet'
ALTER TABLE [dbo].[ScheduleSet]
ADD CONSTRAINT [PK_ScheduleSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ActionSet'
ALTER TABLE [dbo].[ActionSet]
ADD CONSTRAINT [PK_ActionSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'CommandSet'
ALTER TABLE [dbo].[CommandSet]
ADD CONSTRAINT [PK_CommandSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'UnitSet_Camera'
ALTER TABLE [dbo].[UnitSet_Camera]
ADD CONSTRAINT [PK_UnitSet_Camera]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'UnitSet_Tellstick'
ALTER TABLE [dbo].[UnitSet_Tellstick]
ADD CONSTRAINT [PK_UnitSet_Tellstick]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Camera_Id] in table 'ImageSet'
ALTER TABLE [dbo].[ImageSet]
ADD CONSTRAINT [FK_CameraImage]
    FOREIGN KEY ([Camera_Id])
    REFERENCES [dbo].[UnitSet_Camera]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CameraImage'
CREATE INDEX [IX_FK_CameraImage]
ON [dbo].[ImageSet]
    ([Camera_Id]);
GO

-- Creating foreign key on [EventType_Id] in table 'ActionSet'
ALTER TABLE [dbo].[ActionSet]
ADD CONSTRAINT [FK_EventTypeAction]
    FOREIGN KEY ([EventType_Id])
    REFERENCES [dbo].[ActionTypeSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_EventTypeAction'
CREATE INDEX [IX_FK_EventTypeAction]
ON [dbo].[ActionSet]
    ([EventType_Id]);
GO

-- Creating foreign key on [Unit_Id] in table 'ActionSet'
ALTER TABLE [dbo].[ActionSet]
ADD CONSTRAINT [FK_UnitAction]
    FOREIGN KEY ([Unit_Id])
    REFERENCES [dbo].[UnitSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UnitAction'
CREATE INDEX [IX_FK_UnitAction]
ON [dbo].[ActionSet]
    ([Unit_Id]);
GO

-- Creating foreign key on [User_Id] in table 'ActionSet'
ALTER TABLE [dbo].[ActionSet]
ADD CONSTRAINT [FK_UserAction]
    FOREIGN KEY ([User_Id])
    REFERENCES [dbo].[UserSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserAction'
CREATE INDEX [IX_FK_UserAction]
ON [dbo].[ActionSet]
    ([User_Id]);
GO

-- Creating foreign key on [Schedule_Id] in table 'UserSet'
ALTER TABLE [dbo].[UserSet]
ADD CONSTRAINT [FK_ScheduleUser]
    FOREIGN KEY ([Schedule_Id])
    REFERENCES [dbo].[ScheduleSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ScheduleUser'
CREATE INDEX [IX_FK_ScheduleUser]
ON [dbo].[UserSet]
    ([Schedule_Id]);
GO

-- Creating foreign key on [Unit_Id] in table 'CommandSet'
ALTER TABLE [dbo].[CommandSet]
ADD CONSTRAINT [FK_UnitCommand]
    FOREIGN KEY ([Unit_Id])
    REFERENCES [dbo].[UnitSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UnitCommand'
CREATE INDEX [IX_FK_UnitCommand]
ON [dbo].[CommandSet]
    ([Unit_Id]);
GO

-- Creating foreign key on [Id] in table 'UnitSet_Camera'
ALTER TABLE [dbo].[UnitSet_Camera]
ADD CONSTRAINT [FK_Camera_inherits_Unit]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[UnitSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'UnitSet_Tellstick'
ALTER TABLE [dbo].[UnitSet_Tellstick]
ADD CONSTRAINT [FK_Tellstick_inherits_Unit]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[UnitSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------

My question is not the Entity Framework itself, but simple SQL syntax.

In my model, the Camera entity inherits from Unit. I want to make an INSERT to the Camera table, something like this:

INSERT INTO UnitSet_Camera
       (Login,
        Password,
        URL)
 VALUES
       ('myLoginName'
       ,'myPassword'
       ,'http://foo.bar:007');

I also know that this is incomplete because I somehow have to provide my Camera entity with a “Name” (because of the inheritance from table Unit and its’ property “Name”)

How should a full SQL INSERT statement look for an arbitrary Camera entity?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T08:57:12+00:00Added an answer on June 6, 2026 at 8:57 am

    There are two tables, because it’s inheritance – UnitSet has an IDENTITY which is referred to in the derived class. Basically you need to do this:

    INSERT INTO dbo.UnitSet (Name) VALUES ('The Name');
    INSERT INTO UnitSet_Camera
           (Login,
            Password,
            URL,
            Id)
     VALUES
           ('myLoginName'
           ,'myPassword'
           ,'http://foo.bar:007'
           ,SCOPE_IDENTITY());
    

    But there are other things like OUTPUT to do it in a single statement or you could make a view which exposed all the properties of camera and use a trigger to make it updateable.

    But I’m wondering why you want to do this through SQL when you have obviously decided to go through an ORM to do this kind of operation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a Python beginner and have just started using packages. When you're calling a
I am a beginner to iOS development and have just started working with the
I have just started to read about ORMLite so I am still a beginner.
A beginner question I am sure, but I have just started working with a
Ok, I am beginner in JAVA. I have just started. I downloaded Java SE
I just started with fabric.js and I have a (probably beginner) error: I am
Am a beginner in unix and I have just landed into a snag. The
Beginner level question Scenario: Have simple string cocantation tool, that I might expand later
I am an windows developer with over 15 years experience. I have just started
I have a beginner iPhone project going. I have a TableView, which is just

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.