.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Creating a Calculated property to an Entity

Posted By:      Posted Date: April 14, 2011    Points: 0   Category :ASP.Net

Hi there:

I want to add a calculated property to an entity.

I learned that if I create a partial class that extends the entity would suffice.

For example, I'm using the Northwind database, and I'm trying to add a totalAmmount property to Order Details, that should be defined as

UnitPrice * Quantity (let's skip Discount for simplicity).

Then I created the following:

public partial class Order_Detail : EntityObject {

   public double TotalAmmount {

      get {

         return this._Quantity * (double)this._UnitPrice;




But it is not working, I added it to a DataGrid and it didn't show any data. Could somebody tell me what I'm I missing?

View Complete Post

More Related Resource Links

Creating a Generic Entity Framework 4.0 Repository

With .NET 4.0 right around the corner, I thought it would be cool to download Visual Studio 2010 beta 2 and start playing around with the next release of Entity Framework.

The initial release of Entity Framework came with a great deal of criticism. To make matters worse, there was a large uproar when it was rumored that Microsoft would be abandoning LINQ to SQL, in favor of Entity Framework. This was because, at the time, many developers felt Entity Framework was an inferior technology to LINQ to SQL. To set things right, Microsoft proactively moved forward with improving Entity Framework, in time for the 4.0 release of the .NET Framework. This is good news because my initial impressions, so far, have been nothing but positive.

Server-side validation on an Entity Framework required field (property) does not work!

Has anyone had issues getting server-side validation on an Entity Framework required field (property) to work? The data type is a string (nvarchar). Server-side validation for required fields of other data types WORK fine. Only string fields have issues. I get the following error on UpdateModel(obj); of my POST method within the controller. Exception Details: System.Data.ConstraintException: This property cannot be set to a  null value.Source Error: Line 4500:                OnTextChanging(value);Line 4501:                ReportPropertyChanging("Text");Line 4502:                _Text = StructuralObject.SetValidValue(value, false);Line 4503:                ReportPropertyChanged("Text");Line 4504:                OnTextChanged(); I've even tried data annotations like this but it seems to get ignored.     [MetadataType(typeof(ObjMD))]     public partial class Obj     {    

Creating a volume control slider/setting one template property based on another

So, what I want to do, is to make a volume control that looks like a right angle triangle with the 90 degree angle on the bottom right, and then when you click on it, the area to the left of the selected point is shown in a different color.  In other words, I've created a slider with the right background, what I can't do, is work out how to show the selected area by filling in the triangle.  I have worked out how to bind the height of my triangle on the left to the value of the control, but right now, the rate of rise is exactly half of what I need it to be.  I need to know how to change the template for the area to the left of the selection ( which is the repeat button ) so that the background is twice the height that it is right now.  No matter what size I make the slider, the area is always 1/2 the size it needs to be, so I am sure if I could get it to double inside my template, it would work fine. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">       <Style x:Key="SliderButtonStyle" TargetType="{x:Type RepeatButton}">         <Setter Property="SnapsToDevicePixels" Value="true"/>         <

Creating ADO.NET Entity at runtime

I'm trying to implement my own Membership provider. I don't want to dig in very details but only high level logic. And first I don't understand is how can I use the class User generated from database in my CustomMembershipProvider project?I thought I shouldn't generate class User in my project which uses my custom provider because it just don't need any users. It's only for login/logout functionality which implements Membership provider, not project that uses it.Then I thought that I should pass Connection String to my Membership provider in order to make UserEntity somehow and use it inside Membership provider. I have two separate project for Membership provider and for any else project using Membership.So my question is... How could I create and use ADO.NET Entity in CustomMembershipProvider project for User table which located in database in other project?

Error Creating Control - 'asp:UpdatePanelAnimationExtender' could not be set on property 'Animati

It doesn't seem to matter what I try to make the animation do, I keep getting this shown in the designer. No one else on google seems to be getting that problem either. Note: it doesn't cause debugging or runtime issues... in fact, the only negative thing it does is make it extremely annoying when I look at the designer... I'm going to have about 12 of these updatepanelanimations firing everytime the timer ticks too :(. MasterPage file has the toolkitscriptmanager on it. Here is my designer code for the page I'm having the issue on:<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/MasterPage.Master" CodeBehind="TimeLine.aspx.vb" Inherits="TimeLine.WebForm1" %> <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"> <asp:Timer ID="Timer1" runat="server" Interval="7000"> </asp:Timer> <asp:Panel ID="Panel1" runat="server" Height="285px" HorizontalAlign="Center" Width="970px" BackImageUrl="~/Images/Img.jpg"> <br />

Databinding to a property of a child entity.

<asp:Label ID="Label4" runat="server"                         Text='<%# Bind("EmployeeIdSource.EmployeeName") %>'></asp:Label>Is this kind of databinding permitted?

How automatically update a calculated property in wpf

Hi, For example: I have a class MediaList with a list of mediaitems. (Movie, Serie, Season, Episode). All these classes have a property FileSize. So we get this structure: Movie has a property FileSize. Serie has a property FileSize and a property Seasons. Seasons has a property FileSize and a property Episodes. Episode has a property FileSize If have a calculated property FileSize on MediaList that i want to show. If one episode or movie is deleted, the parents fileSize needs to be updated until MediaList.FileSize is updated. What is the best practices to handle this kind of properties? Thx   

Creating custom property on derived Page

I am attempting to accomplish the following during the creation of a Page derived from DerivedPage: <local:DerivedPage xmlns="..." xmlns:x="..." xmlns:local="..." MyProperty="My Value" Title="My Title"> ... </local:DerivedPage> You'll notice an extra property MyProperty in there. The code-behind is like this: class DerivedPage : Page { public string MyProperty { get; set; } ... } When I execute this, I get a null reference in InitializeComponent() when I create a Page derived from DerivedPage. I also tried making MyProperty a dependency property.  But I get the same results. How can I create a property for my new base-class that's set in the markup of my derived class. Thanks, ...Matt

Creating a calculated measure that filters



Can I create a calculated member that will filter out based on a certain dimension? eg, I have a customer dimension and a sales cube. The sales cube has the sales count measure. Can I have a calculated measure that will give me the sales count for all customers that are flagged as 'New'?  That way, I have a total count and a New customer count.



Issue while creating a BCS entity in visual studio for SQL stored procedures


Hi Everyone,

                  I have an issue while creating an entity in Visual studio for SQL stored procedures.I have two input parameters startdate and enddate as datetime datatypes in the stored procedures.I have added two input parameters startdate and enddate in the Readlist and ReadItem methods and created two filter descriptors startdate and enddate of "comparison" type and related these to their respective input parameters.

                 In my readlist and readitem methods I have used LINQ TO SQL query to query the SP.When I debug the program,I am receiving an error message-->remote procedure cannot be debugged.Also my parameters are not being passed to the SP.Any help is appreciated..also if any one has step by step approach,that helps me a lot.

Creating BCS entity for a SQL stored procedure that has parameters using visual studio


Hi Everyone,

                 can anyone help me in creating  BCS entity using BCDM model in visual studio using Linq to sql query for a SQL stored procedure.I am receiving remote debugging error and few other errors.Your step by step approach helps me a lot,I have been playing with this for long,but still no answer.


Thanks ,

Is there a way of creating an Ado.Net Entity Data Model filtered on a Session variables (C#)


I'm trying to customize correct displaying of dropdownlists so information shown in comboboxes is relevant to the kind of user logged on (maintaining referential integrity at data level)

e.g.: I have a user already logged on and depending on his profile I'd like to display to this user only the portion of the database that he would be allowed to see. That would mean that he might have acces to an specific subset of data, e.g.: businesstype = "3", loging level = "2", etc.

Is there a way of creating an Ado.Net Entity Data Model filtered on a Session variables as to maintain proper referential integrity at data level? So it means that the filtering must apply to all entities contained in the .edmx model at once.

Key Columns property when creating dimension hierarchy in Analysis Services 2008


HI All

I have 3 dimensions in our Data Warehouse, dimCampaign, dimCampaignList and dimCampaignTarget
Think of dimCampaign as a marketing campaign, that contains one or more Campaign Lists (offers) for which many customers (dimCampaignTargets) receive.  The are foreign key relationships between these 3 tables, and it is the dimCampaignTarget ids that are written to associated fact tables

I have created a single dimension in Analysis Services 2008 that contains these 3 tables and their respective relationships were set up in the DSV so that I could do this.  Rather than use the 'referenced' dimension method, I wanted a 'single' dimension containing the 3 tables and their snowflake relationships in order that I can create a hierarchy that contains attributes from differing tables (namely the Campaign Description from dimCampaign, and Campaign List Description from dimCampaignList). 

My hierarchy has those 2 levels, top level is Campaign (description), and the 2nd level is Campaign List (description).  The Campaign Targets are not shown in the hierarchy, their attribute is only used in the dimension as the join to most of the fact tables.

Problem is when I set up my hierarchy, I go to change the Key Columns property of the Campaign List attribute to make it a collection of keys (Campaign and Campaign List) as I did in

HELP: Creating an ActionResult method to display a particular database record using Entity Framework


Hi All,

I have an ActionResult method that displays records from a database table (below):

namespace STD.Controllers
    public class StudentController: Controller
        StudentEntities stud;
        public StudentController()
        stud= new StudentEntities ();


        public ActionResult Index()
            ViewData.Model = stud.StudentTable.ToList();
            return View();


I want to design a method "ActionResult Student()" that accepts "Student ID" as a parameter and displays record for that particular student only.

What do I need to do to make this happen? Could anyone please help me with this?

Thanks in advance


An Entity Relationship Diagram Example

An Entity Relationship Diagram conveys a lot of information with a very concise notation. The important part to keep in mind is to limit what you're reading using the following technique:

Choose two entities (e.g. Company and Employee)
Pick one that you're interested in (e.g. how a single Company relates to employees)
Read the notation on the second entity (e.g. the crow's feet with the O above it next to the Employee entity).

Multiple database support with Entity Framework

One of the features introduced in Entity Framework is being database independent. Which mean each database provider can support Entity Framework by implementing its provider.

This feature allows you build applications independent from the underplaying database provider. In this post I'm going to show how to build an application that support multiple databases using same conceptual model made by Entity Framework.

Binding WPF Controls to an Entity Data Model

In this interview, programming writer, McLean Schofield, demonstrates how to bind WPF controls to an entity data model, using Visual Studio 2010 Beta 1. You can also learn more in the topic: Walkthrough: Binding WPF Controls to an Entity Data Model.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend