EF6 Code first inheritance from relationship

I need to create a TPH inheritance on an existing database using EF6 and Code first
Table Person
PersonId (Key)
PersonName
PersonTypeId (FK)
Table PersonType:
PersonTypeId (Key)
Description
Category
The field PersonTypeId is the discriminator for the employees and managers, and the classes that I use are:
class Person
public string PersonId {get; set;}
public string  TypeId {get; set;}
public PersonType Type {get; set}
class Employee : Person
class Manager : Person
I use the fluent API to create the relationship between Person and
PersonType like that:
HasOptional(e => e.Type).WithMany().HasForeignKey(f => f.TypeId);
and it works as expected.
Now, I need to Map the inherintance like that:
 m.Requires("Type.Category").HasValue("EMP");
but it doesn't work because I receive an exception saying that the discriminator field doesn't exist.
Any suggestions??

I try to explain me better
m.Requires("PersonTypeId").HasValue("EMP")
It's ok, but it's not what I need 
The mapping discriminator is not the PersonTypeId but the Category field that is in the class(or table) referred by PersonTypeId
I have more than one values of PersonTypeId that has the same category (employee).
If I choose your solution I need that PersonTypeId has more than one value
Like that:
m.Requires("PersonTypeId").HasValue("1").HasValue("2");
but I know that there isn't this possiblity to have more than 1 value for a discriminator. Is it true?
I try to explain me better
m.Requires("PersonTypeId").HasValue("EMP")
It's ok, but it's not what I need 
The mapping discriminator is not the PersonTypeId but the Category field that is in the class(or table) referred by PersonTypeId
I have more than one values of PersonTypeId that has the same category (employee).
If I choose your solution I need that PersonTypeId has more than one value
Like that:
m.Requires("PersonTypeId").HasValue("1").HasValue("2");
but I know that there isn't this possiblity to have more than 1 value for a discriminator. Is it true?

Similar Messages

  • Entity framework code first inheritance table per type problem

    hello
    i am using ODP.NET version 11.2.0.3.20. i am trying to get entity framework code first to work. one problem i have encountered is with inheritance. i have a "table per type" inheritance scenario. i have 3 tables involved. the base table is called "S_PERIOD" which maps to the base "Period" class. i have a derived table called "S_SEASON_QUARTER" that maps to the derived "Quarter" class. And I have another derived table called "S_SEASON_PRICE_PERIOD" that maps to the derived "PriceBreak" class. for testing purposes i am trying to load all records. the problem is that every class instance ends up being of type "Quarter", which is incorrect. for whatever reason the provider thinks that every "S_PERIOD" record has a corresponding "S_SEASON_QUARTER" record. i took a look at the generated SQL and posted it down below. looking at this SQL it's clear to me why every object ends up being of type "Quarter". It looks like the provider is checking the "C2" field to determine the concrete type to instantiate. the problem however is that the "C2" field value provided by each derived table is ALWAYS equal to "1", which is a problem since this will result in the "case" statement always hitting the second "when" condition. does anyone have any idea how to fix this? thank you
    SELECT
    CASE WHEN (( NOT (("Project1"."C2" = 1) AND ("Project1"."C2" IS NOT NULL))) AND ( NOT (("Project2"."C2" = 1) AND ("Project2"."C2" IS NOT NULL)))) THEN '0X' WHEN (("Project1"."C2" = 1) AND ("Project1"."C2" IS NOT NULL)) THEN '0X0X' ELSE '0X1X' END AS "C1",
    CAST( "Extent1"."PERIOD_ID" AS number(10,0)) AS "C2",
    "Extent1"."START_DATE" AS "START_DATE",
    "Extent1"."END_DATE" AS "END_DATE",
    "Extent1"."NAME" AS "NAME",
    "Extent1"."TYPE_CODE" AS "TYPE_CODE",
    CAST( "Extent1"."CREATE_USER_ID" AS number(10,0)) AS "C3",
    "Extent1"."CREATE_DATE" AS "CREATE_DATE",
    CAST( "Extent1"."MODIFY_USER_ID" AS number(10,0)) AS "C4",
    "Extent1"."MODIFY_DATE" AS "MODIFY_DATE",
    CASE WHEN (( NOT (("Project1"."C2" = 1) AND ("Project1"."C2" IS NOT NULL))) AND ( NOT (("Project2"."C2" = 1) AND ("Project2"."C2" IS NOT NULL)))) THEN NULL WHEN (("Project1"."C2" = 1) AND ("Project1"."C2" IS NOT NULL)) THEN "Project1"."QUARTER_NAME" END AS "C5"
    FROM "DBO_SPACE_DEV"."S_PERIOD" "Extent1"
    LEFT OUTER JOIN (SELECT
         "Extent2"."QUARTER_NAME" AS "QUARTER_NAME",
         CAST( "Extent2"."QUARTER_ID" AS number(10,0)) AS "C1",
         1 AS "C2"
         FROM "DBO_SPACE_DEV"."S_SEASON_QUARTER" "Extent2" ) "Project1" ON ( CAST( "Extent1"."PERIOD_ID" AS number(10,0))) = "Project1"."C1"
    LEFT OUTER JOIN (SELECT
         CAST( "Extent3"."PRICE_PERIOD_ID" AS number(10,0)) AS "C1",
         1 AS "C2"
         FROM "DBO_SPACE_DEV"."S_SEASON_PRICE_PERIOD" "Extent3" ) "Project2" ON ( CAST( "Extent1"."PERIOD_ID" AS number(10,0))) = "Project2"."C1"
    Edited by: 997830 on Apr 3, 2013 8:40 AM

    An update:
    I tried again following this example to the letter:
    Using NuGet to Install and Configure Oracle Data Provider for .NET
    This time I used a console application as described in the example. Yes, I rebuilt the project after the NuGet install.
    I made the appropriate mods to App.config. I get the same error message as with the MVC example above.
    Does the ODP.Net driver really work with EF? If so, can anyone provide me with a working sample project?

  • EF6 Code First: Many to Many Self referencing relationship

    Hi,
    Could any one show me an example for many to many self referencing?
    The scenario is that I have a user table that will contains collection of users as friends.
    Thanks,
    Bo

    Hi Kalman,
    Really appreciate your answer.
    I just wonder if I can, alternatively, set up tables as below,
    Public class user
    public int userId{get; set;}
        public
    virtual
    ICollection<User> CircleOneFriends { get; set; }
        public virtual ICollection<User>
    CircleTwoFriends { get; set; }
       public User()
    CircleOneFriends
    = new HashSet<User>();
    CircleTwoFriends = new HashSet<User>();
    public class UserConfiguration : EntityTypeConfiguration<User>
        public
    UserConfiguration()
           this.HasMany(x=>x.CircleOneFriends) .WithMany(x=>x.CircleTwoFriends).Map(x=>x.ToTable("Friends"))
    Do you think that will work in my case?
    Thanks a lot,
    Bo

  • How to specifiy the provider to be Oracle.ManagedDataAccess.Client when creating a dynamic connection string with EF Code First from Database?

    I am trying to use the relatively new Code First from Database with the newest EF (6.x) and on an Oracle database (11g, but I have installed the newest ODTwithODAC). First of all, it works fine as long as the connection string is inside the App.Config file. But when I try to build it dynamically in the C# code (or rather, statically at the moment) it fails. I have it working with a dynamically built connection string when doing Model from Database though, so I'm at a loss right now.
    First, I have created a second constructor for the context class that takes a string and does base(connectionString). Then I build the connection string via
    OracleConnectionStringBuilder oracleBuilder = new OracleConnectionStringBuilder();
    oracleBuilder.DataSource = "TEST.BLA.COM";
    oracleBuilder.UserID = "ABC";
    oracleBuilder.Password = "abc";
    oracleBuilder.PersistSecurityInfo = true;
    string connection = oracleBuilder.ToStrin();
    Now trying to open an EntityConnection by giving to it this provider-specific connection string (or even the static one from the App.Config) doesn't work; I get "keyword not supported: user id"). Trying it by creating a context and giving this connection string doesn't work either. I'm pretty sure that this is because I didn't specify the provider to use; after all, it should use the Oracle.ManagedDataAccess.Client provider and not an SQL Server based one.
    I then tried to get around this by using an EntityConnectionStringBuilder on top and specifying the provider keyword there, but then I get "keyword not supported: provider" when using it in the context constructor, and "the 'metadata' keyword is always required" when using it with the EntityConnection constructor.
    As I said above: I bet it's the provider that I have to specify somehow, but I don't know how. The code that does work is the following:
    using (var context = new Model())
    context.Database.Connection.Open();
    context.Database.Connection.Close();
    When I read context.Database.Connection.ConnectionString, it is exactly the provider-specific connection string I created above, but I don't know where to specify the provider again. Do you know of any way to do this? Certainly there must be one.
    PS: I have also posted this question on http://stackoverflow.com/questions/27979454/ef-code-first-from-database-with-managed-oracle-data-access-dynamic-connection because it is quite urgent and I'd like to use Code First from Database. Otherwise I'd have to go "back" to using Model from Database again, which is not ideal because we have updatable views where the .edmx-file has to be edited after every reload of the model, while with Code First from DB inserting into the view automatically works.

    I am trying to use the relatively new Code First from Database with the newest EF (6.x) and on an Oracle database (11g, but I have installed the newest ODTwithODAC). First of all, it works fine as long as the connection string is inside the App.Config file. But when I try to build it dynamically in the C# code (or rather, statically at the moment) it fails. I have it working with a dynamically built connection string when doing Model from Database though, so I'm at a loss right now.
    First, I have created a second constructor for the context class that takes a string and does base(connectionString). Then I build the connection string via
    OracleConnectionStringBuilder oracleBuilder = new OracleConnectionStringBuilder();
    oracleBuilder.DataSource = "TEST.BLA.COM";
    oracleBuilder.UserID = "ABC";
    oracleBuilder.Password = "abc";
    oracleBuilder.PersistSecurityInfo = true;
    string connection = oracleBuilder.ToStrin();
    Now trying to open an EntityConnection by giving to it this provider-specific connection string (or even the static one from the App.Config) doesn't work; I get "keyword not supported: user id"). Trying it by creating a context and giving this connection string doesn't work either. I'm pretty sure that this is because I didn't specify the provider to use; after all, it should use the Oracle.ManagedDataAccess.Client provider and not an SQL Server based one.
    I then tried to get around this by using an EntityConnectionStringBuilder on top and specifying the provider keyword there, but then I get "keyword not supported: provider" when using it in the context constructor, and "the 'metadata' keyword is always required" when using it with the EntityConnection constructor.
    As I said above: I bet it's the provider that I have to specify somehow, but I don't know how. The code that does work is the following:
    using (var context = new Model())
    context.Database.Connection.Open();
    context.Database.Connection.Close();
    When I read context.Database.Connection.ConnectionString, it is exactly the provider-specific connection string I created above, but I don't know where to specify the provider again. Do you know of any way to do this? Certainly there must be one.
    PS: I have also posted this question on http://stackoverflow.com/questions/27979454/ef-code-first-from-database-with-managed-oracle-data-access-dynamic-connection because it is quite urgent and I'd like to use Code First from Database. Otherwise I'd have to go "back" to using Model from Database again, which is not ideal because we have updatable views where the .edmx-file has to be edited after every reload of the model, while with Code First from DB inserting into the view automatically works.

  • Calling Oracle stored procedure with out param of user define type from Entity Framework 5 with code first

    Guys i am using Entity Framework 5 code first (I am not using edmx) with Oracle and all works good, Now i am trying to get data from stored procedure which is under package but stored procedure have out param which is user define type, Now my question is
    how i will call stored procedure from entity framework
    Thanks in advance.

    I agree with you, but issue is we have lots of existing store procedure, which we need to call where damn required. I am sure those will be few but still i need to find out.
    If you think you are going to get existing MS Stored Procedures  or Oracle Packages that had nothing to do with the ORM previously to work that are not geared to do simple CRUD operations with the ORM and the database tables, you have a rude awakening
    coming that's for sure. You had better look into using ADO.NET and Oracle Command objects and call those Oracle Packages by those means and use a datareader.
    You could use the EF backdoor, call Oracle Command object and use the Packages,  if that's even possible, just like you can use MS SQL Server Stored Procedures or in-line T-SQL via the EF backdoor.
    That's about your best shot.
    http://blogs.msdn.com/b/alexj/archive/2009/11/07/tip-41-how-to-execute-t-sql-directly-against-the-database.aspx

  • Can't map Booleans from native SQL queries with Code First, EF 6, ODAC 12c R3 (Beta 2)

    We're using Code First, EF 6, ODAC 12c R3 (Beta 2). When I use LINQ-to-Entities, I can map NUMBER(1) to Boolean fields as documented here: https://docs.oracle.com/cd/E56485_01/win.121/e55744/entityDataTypeMapping.htm#ODPNT8300
    <oracle.manageddataaccess.client>
      <version number="*">
      <edmMappings>
        <edmMapping dataType="number">
          <add name="bool" precision="1"/>
          <add name="byte" precision="3" />
          <add name="int16" precision="4" />
          <add name="int32" precision="9" />
          <add name="int64" precision="18" />
        </edmMapping>
      </edmMappings>
      </version>
    </oracle.manageddataaccess.client>
    So far, so good:
        [Table("USER_PROFILE")]
        public class UserProfile
            [Key]
            [Column("LOGIN_ID", Order = 1)]
            public string LoginId { get; set; }
            [Column("IS_SUPER_USER")]
            public bool? IsSuperUser { get; set; }
    var query = db.UserProfiles.Take(20);
    However, when I try to map to the same class from native SQL, I get an exception:
    // The real query is much more complex. This is just an example.
    private const string AllProfilesSql = @"
                SELECT login_id AS LoginId, is_super_user AS IsSuperUser
                FROM user_profile
    var query = db.Database.SqlQuery<UserProfile>(AllProfilesSql).Take(20);
    >The 'IsSuperUser' property on 'UserProfile' could not be set to a 'System.Int16' value. You must set this property to a non-null value of type 'System.Boolean'.
    Do you know any solutions or workarounds for this? Is it a bug?

    Hmm, a feature request is possible; however, I'm not sure how feasible it would be to implement (if it is possible at all) in this scenario.
    The challenge is that when using SqlQuery like this, EF calls into our override of the ExecuteDbDataReader method in OracleCommand (via System.Data.Common.DbCommand.ExecuteReader). That in and of itself is not an issue it's just that we don't know that this call is from EF and so we should use the EDM mappings from the configuration. In a "normal EF" scenario we know the call is from an EF "source" so can respond accordingly and perform the mapping.

  • How to create ForeignKey reference to code-first identity tables.

    Hi,
    I'm developing a web application using MVC 5, EntityFramework 6 with a Code-First approach.
    I have successfully created my tables dbo.AspNetRoles, dbo.AspNetUsers... etc, also I have created some custom tables for example a table that must have a relationship between the menus presented and the role of the authenticated user. What I want to add
    to my model is a property like this:
    [ForeignKey]public virtual AspNetRoles Roles { get; set; }
    But of course I have not an AspNetRoles class, because the framework auto generates the tables only in the SQL database, so my question is, I have to manually create this classes? How can I link them to the database tables, I think the issue may be deeper.
    If I can't do this maybe I should go back to SQL manual queries.
    Thanks!

    Hello Morral,
    >> What I want to add to my model is a property like this:
    If you have a separate model to store your own business model, what you have written should be almost ok, however, please take care the [ForeignKey] attribute is usually used to markup a property as an integer property to specify it as a foreign key:
    public virtual int RoleID { get; set; } [ForeignKey("RoleID")] 
    public virtual AspNetRoles Roles { get; set; }
    Or it would generated a combinatorial name.
    >> But of course I have not an AspNetRoles class, because the framework auto generates the tables only in the SQL database, so my question is, I have to manually create this classes?
    From your description, the AspNetRoles class seems to be a system class which is not exposed to user. If so, these classes already exists, you do not need to create them again.
    I notice that you are working with the MVC project, you could also ask this issue to the MVC forum:
    http://forums.asp.net/1146.aspx
    There are MVC experts will help you.
    Regards.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Mapping Property Names in EF6 Database First

    Hi
    I am just starting out with EF6 and am hoping I will be able to do what i am wishing:
    using DB first:
    say I have the following:
    database name "a1234"
    with table named "a"
    with column names "a1", "a2",
    with table named "b"
    with column names "b1", "b2",
    know is my wish:
    within my coding I would like:
    to use table name "customers" and EF6 would know to go to table name "a".
    to use column name "firstname" in table name "customers" and EF6 would know to go to table name "a" and column name "a1".
    the data types and all other elements would stay the same. If this is not a option then I would be happy to try a work around by having 2 copes of the database and then make 2 projects generate EF6 in each then strip away the EF code from the first point
    from the database in the one using the full names in the database and then strip away the code from the second point from the database in EF to joint the code and add some mapping at the joint point of the EF code?
    Would anyone be able to help me with this and let me know if it is possible or not?
    Simon
    Thanks Simon

    Hello Simon,
    >>within my coding I would like: to use table name "customers" and EF6 would know to go to table name "a"…
    No, Entity Framework would generate these names of databases, tables and columns by the wizard which we cannot customize, these names would only be plurals or not decided by you check or not check the plurals checkbox.
    Regards.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Cost Center Inheritance from Org Unit

    Good day all,
    Can someone please advise regarding cost center inheritance from org units?
    I understand the inheritance concept, however simple need to know if the CCenter is added to the org unit via A011 relationship, does the system physically create a A011 relationship on the position inhertiting the cost center from the org or does the system simply pick up the realtionship from the org unit relationsip for use in IT0001 field KOSTL (cost center)?
    Thanks guys, have a lovely day!
    Christy

    Hi Christy,
    As we know cost centre(K) is an unusual object in OM.Two type of objects internal  whose master record are in database table beloging to sap erp hcm and eexternal object whose master data belong to other application areas.Cost centre is an external object that is used to represent origin of costs.Inheritance concept is on the basis of whoch cost centre are assigned in org plan.
    directly related cost centre is called master cost centre and they are made via A011 cost centre assignment relationsip.they can be made at org unit,position or work centre and nornmally its org unit that common.Org unit at the top are asisgned the cost centre as a best practise so that all the org units below or reporting will inherit the same.
    Similarly multiple cost centre assignments can also e made through 1018 infotype(cost centre distribution).Inheritance also applied to them aswell.
    Hope this helps.
    No Worries
    KG

  • Default tax code in PO from Condition record :::::::

    Hello experts
    If a condition record for a plant vendor material combination  is maintained for a particular tax code , is it possible to default the tax code maintained in PO from the condition record??
    Pls give ur valuable inputs
    Regards
    Anis

    from Note 214151 - Tax processing in purchasing
    . Determination of the tax code
    The tax code is defaulted from the purchasing info record in the purchase order item, however, it can also be determined via the conditions. During the determination via the condition technique an access sequence is assigned in the standard system of condition NAVS. With the latter, different tax codes can be stored via the normal condition maintenance depending on tax indicators (material, plant, account assignment, origin). Basically this access sequence can also be assigned to other condition types. The tax code is only transferred to the purchase order if class "D" (taxes) is the condition type. If several condition types of this type exist in the purchase order item, the first one that contains a tax code is transferred.

  • Help - Print first page from different tray

    Hi,
    I print seveal booklets and with my old printer (1200) was able to print the first page from the second tray. That is to have the cover page in a different color and weight paper.
    How do I do this with collated printing with my new Officejet 8500 Pro all in one printer. The option does not appear in the print options as it did for the driver for for the old 1200 printer. 
    I am currently using Vista is this option available with windows 7.
    I will be glad for any help you can give me.
    Regards
    Eddie

    This forum is more focused on consumer level products (and issues).  You may have better results asking in the  Laserjet Small/Medium Business Support Forum here.
    If you are printing directly from a Java app you will probably need to embed tray selection codes as described in this post.
    Bob Headrick,  HP Expert
    I am not an employee of HP, I am a volunteer posting here on my own time.
    If your problem is solved please click the "Accept as Solution" button ------------V
    If my answer was helpful please click the "Thumbs Up" to say "Thank You"--V

  • What is wrong by inheriting from Object?

    Hi and thank you for reading my question,
    I have tried the following program:
    import java.util.*;
    interface I {}
    class A1 {}
    class B1 extends A1  implements I {
        B1() {}
    class B2 extends A1 implements I {
        B2() {}
    class Cell<V> 
    V  value;
    <T extends V> Cell(T a) {value = a;}
    V get() { return value; }
    class Foo {
        void  test(boolean b){
         Cell<? extends B1> cb1 = new Cell<B1>(new B1());
         Cell<? extends B2> cb2 = new Cell<B2>(new B2());
         Cell<? extends I> c1 = ( b ? cb1 : cb2);
         Cell<? extends A1> c2 = ( b ? cb1 : cb2);
    }and I have got the following error:
    Test.java:31: incompatible types
    found   : Cell<capture of ? extends java.lang.Object&I&A1>
    required: Cell<? extends A1>
         Cell<? extends A1> c2 = ( b ? cb1 : cb2);
                                     ^
    1 errorWhy c2 is incorrect and c1 is correct?
    It seems that there is a bug by inheriting from Object.
    I have tried the same code but now class A extends
    a class different than Object:
    import java.util.*;
    interface I {}
    class A1 extends Vector<Integer>{}
    class B1 extends A1  implements I {
        B1() {}
    class B2 extends A1 implements I {
        B2() {}
    class Cell<V> 
    V  value;
    <T extends V> Cell(T a) {value = a;}
    V get() { return value; }
    class Foo {
        void  test(boolean b){
         Cell<? extends B1> cb1 = new Cell<B1>(new B1());
         Cell<? extends B2> cb2 = new Cell<B2>(new B2());
         Cell<? extends I> c1 = ( b ? cb1 : cb2);
         Cell<? extends A1> c2 = ( b ? cb1 : cb2);
    }This program compiles without any error. Both c1 and c2 are correct.

    A bug, I've submitted bug 6278798.

  • Migrating from eVC++4.0 to VS2008: Menu Bar not coming for class inherited from CProterty sheet

    We are migrating code developed in eVC++4.0 to Visual Studio 2008. We are facing a Problem as descripted below. We are using Pocket PC 2003 emulator.
    We are creating a class inherited from CPropertySheet. As below:
    In Header File:
    class COptionsSheet :
    public CPropertySheet
          DECLARE_DYNAMIC(COptionsSheet)
    #if(WINVER == 0x400)// This works for MenuBAr inherited from CDialog classes.
          CCommandBar m_cb;
    #else
          CCeCommandBar m_cb;
    #endif
    public:
    virtual BOOL OnInitDialog();
    We are drawing menu bar on the property window as below:
    In .CPP file:
    IMPLEMENT_DYNAMIC(COrderSheet, CPropertySheet)
    BEGIN_MESSAGE_MAP(COrderSheet, CPropertySheet)
    ON_COMMAND(ID_CUSTOMER_COLLECTPAYMENT, OnCustomerCollectpayment)
    ON_WM_INITMENUPOPUP()
    ON_NOTIFY(GN_CONTEXTMENU, 0, OnContextMenu)
    END_MESSAGE_MAP()
    BOOL COrderSheet::OnInitDialog()
    BOOL bResult = CPropertySheet::OnInitDialog();
    m_cb.Create(this);//This we have changed for VS 2008 as menu was not appearing for class inherited from CDialog class as well. In eVC++
    4.0 code we have used. Please see m_cb in header file discription
    m_cb.InsertMenuBar(IDR_ORDER1);// This calis unable to draw mwnu bar
    CMenu *pMenu = CWnd::GetMenu();
    //pMenu becomes NULL in very next line as we are passing it as parameter below.
    gPromotion.LoadSalesPromotions(pMenu,
    "Sales", SRC_TRACE_START);
    We tried this as well but it’s also not working:
    CMenu *pMenu = new CMenu;
          BOOL cehckStatus = pMenu->LoadMenu(IDR_ORDER1);
    SetMenu(pMenu);
          CRect r;  GetWindowRect(&r);
          r.bottom += GetSystemMetrics(SM_CYMENU);
          MoveWindow(r);
    Do we have to change or add something more for the menu bar in case of Property Sheet. Is there any change between eVC++ and Visual studio 2008 that we need to incorporate here.

    This forum is for POSReady. Please try one of the Windows CE forums:
    http://social.msdn.microsoft.com/Forums/en-US/category/windowsembeddedcompact
    -Sean
    www.annabooks.com / www.seanliming.com / Book Author - Pro Guide to WE8S, Pro Guide to WES 7, Pro Guide to POS for .NET

  • Inheriting from MovieClip

    Hi all,
    I'm new to Flash and I'm new to OOP, and so I'm having a bit
    of trouble writing ActionScript programs to do exactly what I want.
    I am trying to create a simple application, in which a
    MovieClip is dragged around the screen and a textbox gets updated
    with the MovieClip's coordinates somewhere else on the screen. I
    wanted to do this using custom classes, so I created a class called
    MovieClipCoordinates that would contain a MovieClip and a
    TextField. I am initializing the MovieClip as the output of a
    this.createEmptyMovieClip() of the main movie, and the TextField
    similarly.
    My intention is to have the TextField updated whenever the
    MovieClip is dragged. So, in the onRelease function of the
    MovieClip, I need to update the TextField of the
    MovieClipCoordinates object that the MovieClip is a property of.
    The problem is, I have no idea how to find out the
    MovieClipCoordinates that the MovieClip belongs to. I thought I
    would create a method in the MovieClipCoordinates class that would
    set the TextField, which would be called from the
    MovieClip.onRelease. So I figured I would not have a MovieClip
    inside the MovieClipCoordinates class, but instead another class
    inherited from MovieClip which also contains a reference to the
    MovieClipCoordinates class that it is a member of. However, the
    problem now is that I can no longer create this subclass through a
    call to createEmptyMovieClip. So how do I create it?
    I'm getting a bit confused at this point of time. Could
    someone please give me some idea of how to do this?
    Thanks.
    Ajit

    LuigiL,
    Thank you very much for your assistance. I truly appreciate
    it.
    Though the code works perfectly, I wonder if I may trouble
    you to clarify a couple of questions that I have with your code.
    Looking particularly at this section of the code:
    private function setHandlers(target_mc:MovieClip):Void{
    //use a reference to the current object
    var thisObj:MovieClipCoordinates=this;
    target_mc.onPress=function():Void{
    this.startDrag();
    target_mc.onRelease=function():Void{
    this.stopDrag();
    //get the new coordinates
    var thisX=thisObj.box_mc._x;
    var thisY=thisObj.box_mc._y;
    //and refresh the text
    thisObj.printCoordinates(thisX,thisY);
    How is it legal to use thisObj inside the onRelease function?
    I was under the impression that the onRelease function is a
    separate function altogether, that is called in the context of the
    MovieClip that it is associated with. How does it have knowledge of
    thisObj, which was defined in scope above it?
    Would it be even possible to define the onPress and onRelease
    functions above as two separate functions (CoordinatesPress and
    CoordinatesRelease, for example) and rewrite the above code as
    follows?:
    private function setHandlers(target_mc:MovieClip):Void{
    //use a reference to the current object
    var thisObj:MovieClipCoordinates=this;
    target_mc.onPress=CoordinatesPress;
    target_mc.onRelease=CoordinatesRelease;
    defining the handler functions separately. If I chose to do
    this, how would I possibly pass the thisObj to the handlers?
    I seem to be missing something fundamental in ActionScript
    functions, or perhaps just in the event-handlers. I would
    appreciate it if you could help me clear this up.
    Thanks again,
    Ajit

  • Business area is Inherited from debit line in MIRO

    Dear All,
    I have a question that after we have upgraded the system from R/3 4.7 to ECC 6.0, we found that when the invoice is posted against PO via transaction code MIRO, the business area of Debit side is Inherited to the credit side (vendor line)
    For example:
    In our R/3 4.7 environment. the invoice against PO is as below:
    31 (CR) Vendor:123   (No Business Area)
    81 (DR) Business Area:0001 Cost Center: A
    But after upgrade, the entries become:
    31 (CR) Business Area:0001 Vendor:123   (The business area is Inherited from debit line)
    81 (DR) Business Area:0001 Cost Center: A
    Do you have any suggestions, so that we can have the same behavior as R/3 4.7?
    Thanks very much.
    Sunny

    Hi
    It seems that you have document splitting active in your system and hence the system is deriving the Business Area from the debit line item. This is the correct way, as you may have multiple  Business Area and he vendor liability should be splitted so that the financial statement are balanced at the Business Area level. If you still want to enter business area in vendor line item, while keying in the vendor invoice, you can do so. but in case, there are multiple business area in the invoice, you should also identify how the splitting will occur for vendor liability, if you enter, business area at the vendor line item.
    Regards
    Sanil Bhandari

Maybe you are looking for