Identity Return from savechanges but from object type.

Hi, 
I have written my code as follows
public int createPerson(PERSON ObjPersonProfile)
            int i = 0;
            if (ObjPersonProfile != null)
                i = dataAdaptor.save(ObjPersonProfile);
            return i;
 public int save(object oObject)
            try
                SQLAdaptor ida = new SQLAdaptor();
                EntityConnectionStringBuilder ecb = ida.efConnstr();
                ef6Entities pef6Entities = new ef6Entities(ecb.ConnectionString);
                 pef6Entities.AddObject(oObject.GetType().Name + "s", oObject);
                 pef6Entities.SaveChanges();
            catch (Exception ex)
            return 1;
This is a common save method (http://geekswithblogs.net/danemorgridge/archive/2009/12/02/entity-framework-tip-building-a-reusable-save-method.aspx) which can be used for all entities. But now i need to return the latest id. This can be achieved in normal
scenario by <entity>.id. But i am not able to do so beacuse of the object type. Can some one tell me how i can return the new created value?
Thanks
Prachin Soparkar

Hello Prachin Soparkar,
>>But i am not able to do so beacuse of the object type. Can some one tell me how i can return the new created value?
You could try to use refection since the object type would be obtained at run time, and from the edmx medadata workspace, to obtain these primary key properties, and compare the object type property to check if current property is a PK, if so, set it value
and return it, here I made a demo, you could have a try:
class Program
static void Main(string[] args)
Order order = new Order() { OrderID = 3, OrderName = "3" };
var lastID = Save(order);
private static int Save(object order)
var lastID = 0;
using (DFDBEntities db = new DFDBEntities())
ObjectContext context = ((IObjectContextAdapter)db).ObjectContext;
context.AddObject(order.GetType().Name, order);
context.SaveChanges();
ReadOnlyMetadataCollection<EdmMember> PKs = (ReadOnlyMetadataCollection<EdmMember>)context.MetadataWorkspace.GetItems(DataSpace.CSpace).FirstOrDefault(i => i.BuiltInTypeKind.ToString() == "EntityType" && i.MetadataProperties["Name"].Value.ToString() == order.GetType().Name).MetadataProperties["KeyMembers"].Value;
var properties = order.GetType().GetProperties();
foreach (var property in properties)
if (PKs.Select(s => s.Name).Contains(property.Name))
lastID = (int)property.GetValue(order);
return lastID;
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.

Similar Messages

  • Listener actually up as seen from backend but from console gets error

    Hi
    My SCAN listener is shown running from backend but is shown down from console.
    response for listener shows below error.
    Any suggestions/hints
    Thanks
    LSNRCTL for Linux: Version 11.2.0.2.0 - Production on 06-JUNE-2011 11:44:54 Copyright (c) 1991, 2010, Oracle. All rights reserved. Welcome to LSNRCTL, type "help" for information. LSNRCTL> Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER_SCAN1))) TNS-12541: TNS:no listener TNS-12560: TNS:protocol adapter error TNS-00511: No listener Linux Error: 2: No such file or directory LSNRCTL>

    Thank you for your help.
    I am using a RAC database and this is the status
    srvctl status scan_listenerSCAN Listener LISTENER_SCAN1 is enabled
    SCAN listener LISTENER_SCAN1 is running on node oradb123
    SCAN Listener LISTENER_SCAN2 is enabled
    SCAN listener LISTENER_SCAN2 is running on node oradb124
    SCAN Listener LISTENER_SCAN3 is enabled
    SCAN listener LISTENER_SCAN3 is running on node oradb124
    srvctl config scan_listenerSCAN Listener LISTENER_SCAN1 exists. Port: TCP:1730
    SCAN Listener LISTENER_SCAN2 exists. Port: TCP:1730
    SCAN Listener LISTENER_SCAN3 exists. Port: TCP:1730
    [ oradb469:/home/oracle ]
    srvctl config scanSCAN name: oemcrsp-xyz.net, Network:
    1/10.180.5.0/255.255.255.0/eth0
    SCAN VIP name: scan1, IP: /oemcrsp-xyz.net/10.180.5.186
    SCAN VIP name: scan2, IP: /oemcrsp-xyz.net/10.180.5.187
    SCAN VIP name: scan3, IP: /oemcrsp-xyz.net/10.180.5.185

  • Remove spaces when generating xml from data mapped on object types

    My problem is kind of complex so I'll try to reduce it to a more manageable example:
    drop type msm force;
    drop type list_msm force;
    create type msm as object(
         nume char(20)
    create type list_msm as table of msm;
    select xmlserialize (document xmlelement("values",
         cast(multiset(
              select trim(p.den) from produse p) as list_msm
         ) as clob indent size=2
         ) as "xml"
         from dual;
    This is where it gets tricky.
    p.den is a field that contains spaces. I use trim(p.den) to remove them but because I cast this to list_msm, the values are then again mapped into msm objects, which have the "nume" field of char(20). So.. when generating the XML, the output still contains spaces.
    This is an excerpt of the result:
    <values>
    <LIST_MSM>
    <MSM>
    <NUME>Prod.1 </NUME>
    </MSM>
    <MSM>
    <NUME>Prod.2 </NUME>
    </MSM>
    <MSM>
    <NUME>Prod.3 </NUME>
    </MSM>
    <Later.. I see that the forum removes the extra spaces but I ensure you that after eg. "Prod.1" there are a lot of spaces, as the original field from the "produse" table is defined as char(20))
    So.. Is there a way to generate the XML without those extra spaces? Basically, I want to be able to trim them before I send them to the xml serializer, but the problem is that i have no control over the whole casting thing ( oracle magic happening that automatically creates all the xmlelements needed, etc.)
    Somehow, when the xml engine steps over the collection and accesses the fields, somehow, i need a trim there. Maybe some kind of accesor for the fields in the type can be declared so that the xml engine uses it instead of the field itself directly. The accesor would then return trim(field). Sorry for this mumbo jumbo gibberish but I want to be as clear as possible.
    Edited by: user9229988 on May 10, 2012 9:24 AM
    Edited by: user9229988 on May 10, 2012 9:25 AM
    Edited by: user9229988 on May 10, 2012 9:38 AM

    Hi.
    Check this:
    drop type msm force;
    drop type list_msm force;
    create type msm as object(
    nume VARchar2(20)     --VARCHAR2 NOT CHAR
    create type list_msm as table of msm;
    create table produse
    den char(20)
    INSERT INTO produse VALUES('Prod.1');
    INSERT INTO produse VALUES('Prod.2');
    INSERT INTO produse VALUES('Prod.3');
    COMMIT;
    select xmlserialize (document xmlelement("values",
    cast(multiset(
    select trim(p.den) from produse p) as list_msm
    ) as clob indent size=2
    ) as "xml"
    from dual;
    <values>
      <LIST_MSM>
        <MSM>
          <NUME>Prod.1</NUME>
        </MSM>
        <MSM>
          <NUME>Prod.2</NUME>
        </MSM>
        <MSM>
          <NUME>Prod.3</NUME>
        </MSM>
      </LIST_MSM>
    </values>Hope this helps.

  • Trying to access server remotely. Have Static IP from ISP but if I type that address into browser I get router login page. How do I get RDP

    Hi Guys, Please help.  I am trying to run remote desktop from internet.  I have just been given a static IP address from my ISP and when I type it into browser I get router login page.  I want to be able to use Remote Desktop.  I can
    use RDP on the LAN and works great but not from external (internet).  I don't know how to get static IP address to open windows login page or RDP to connect when I put IP address into RDP..  I have Windows 2003 server running. 

    Check your router for free ports. You may use http port number "80" to port forward the request to your server. In your firewall settings, create a new rule to allow incoming http request. Before that enable NAT in your router for LAN and assign
    a static IP address for the server machine. It would make port forwarding easier.

  • Mb1b movement 453 - profit center not from material but from sales order

    Dear All,
    we have the problem that by return process from sales order stock to free stock (453 movement) we would like to have the original Profit center from sales order, but as SAP standard it moves PC from material master.
    we have implemented already oss 978159 sowie 1038490, but did not help.
    Since days we try to find an uxer exit in MM or CO!? where we could write in the correct profit center. But unfortunately PC from material master pops up at the end of the process, and the system overwrites it again and again.
    Had sy of you similair problem? can you please help with an user exit?
    Thanks,
    BB

    Hi
    I think this behaviour is correct.. Since you are moving from Sales order stock to Unrestricted stock, the PC from mat master would prevail...
    As far as I know, this behaviour is correct
    Regards
    Ajay M

  • Database Server - SQL Access: Cannot connect from code but from SSMS

    Hi,
    I am using following connection string in my asp.net web.config:
    [Less than symbol] add name="FMMConnectionString" connectionString="Data Source=xxxxxxxxx,1234;Initial Catalog=Test1Db;User Id=Rajeev;Password=xxxxxxxxxxxxx;" providerName="System.Data.SqlClient" [Slash][Greater than symbol]
    The database is on remote database server. The sql user/ developer 'Rajeev' is deliberately given restricted permissions (to protect our schema) using following sql commands:
    GRANT ALTER,EXECUTE, SELECT,INSERT,UPDATE,DELETE ON SCHEMA ::dbo TO Rajeev
    DENY VIEW DEFINITION ON SCHEMA::dbo TO Rajeev;
    GRANT CREATE PROCEDURE TO Rajeev;
    GRANT CREATE FUNCTION TO Rajeev;
    DENY ALTER ON SCHEMA::dbo TO Rajeev; -- To disallow Rajeev to create objects on dbo schema but only create in Rajeev schema while still being able to select, insert, execute on dbo schema. 
    The above connection string works perfectly fine when used from Visual Studio> Server Explorer. I am able to execute following sql queries without issues. Same is true when using SQL Server Management Studio using Rajeev credentials.
    select top 100 * from XYZEmployees
    execute usp_GetMMBSchemeDetails '1' 
    The error I get in web page is following:
    The stored procedure 'usp_GetMMBSchemeDetails' doesn't exist.
    When I ran code using breakpoints to see what is happening, I see that when connection object is being instantiated, the connection state is being closed with following error:
    at System.Data.SqlClient.SqlConnection.GetOpenConnection()
    at System.Data.SqlClient.SqlConnection.get_ServerVersion()
    I turned off my firewall to see if it was blocking but it did not help. I tried using Visual Studio 2012 as well as Visual Studio 2013 but same issue showed up.
    Kindly let me know why I am able to execute sql queries from SSMS and Visual Studio's Server Explorer but not from application code. Is there something that needs to be enabled on remote database server so that the queries can run from code? I like to create
    more users like Rajeev with restricted permissions to develop my application. So kindly provide a solution if you know.
    Thanks,
    Pullet

    Thanks Everyone for your insights :) 
    RSingh, Your approach works when using SSMS, not when called from application code (example: asp.net code-behind page calling a stored proc using connection object).
    My requirement is, I only wanted developer to do front end programming without having the ability to look at backend sql objects definitions. He/she can call the sql objects in the program as needed. 
    I am able to finally solve this requirement by following approach. Hope it helps others. 
    1. Right-click Rajeev user in Database> Security>Users and unselect 'dbowner' from 'General' tab> 'Database Role Membership' section even though Default Schema shows up as Rajeev schema. Now, this user can't do anything on dbo schema of database
    (as well as in any other user's schema in this database).
    2. Ran above commands but excluded following command which was identified as root-cause.
    DENY VIEW DEFINITION ON SCHEMA::dbo TO Rajeev;
    3. Now ran a script that denies 'view definition' of dbo schema's tables. It loops through all tables and denies 'view definition' on each table. Adapted the script of http://blog.extreme-advice.com/2013/01/23/grant-view-defination-permission-to-all-stored-procedures-in-sql-server/.
    Now, the user Rajeev can execute dbo schema objects both from SSMS as well as from application code.
    4. DENY EXECUTE, SELECT ON SCHEMA::INFORMATION_SCHEMA TO Rajeev; -- Restricts Rajeev from executing INFORMATION_SCHEMA objects seen in SSMS.
    However one remaining open item is, I could not hide the system objects (which are part of sys schema) in SSMS. Ideally, I do not want Rajeev to execute the 'system views', 'system stored procedures', etc. When I execute same command (below command), it
    runs without errors but does not apply this restriction.
    DENY EXECUTE, SELECT ON SCHEMA::sys TO Rajeev;
    If you know the reason why it is happening like this, please kindly share.
    Cheers,
    Pullet
    Cheers | Pullet

  • Running shell command from Java, but from Windows Schedule Task?

    I have a simple java program that will start a dos based program. The java program works great when I run it, but when I run it from the Windows Task Scheduler, the dox box that should pop up, does not. It is running because I can see it in the task manager but I can not see the command window.
    Any ideas how to show the command window from a java application that is ran from Windows Task Scheduler?
    Example program below. Runs fine by itself, should get a dos popup that issues the directory command, run it from the scheduler and it does not show the dos box. You can however see it in the Processes as CMD.exe.
    import java.io.IOException;
    public class Test {
          * @param args
         public static void main(String[] args) {
              try {
                   Runtime.getRuntime().exec("cmd /k start dir");
              } catch (IOException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
    }Now the my real program is quite a bit more complicated. It actually goes out and checks the status of an Oracle Database, if all the tablespaces are online, then the middle tier application is allowed to start. The middle tier application is started by my java application, and is comes up with a dos console which shows status and users connected to the database.

    Jag,
    Actually, the question of whether it works for me seems to depend on the version of the OS (or Oracle). On RedHat Linux (Oracle 8.1.6) it didn't work at all, but on Solaris (Oracle 9.0.2) it did. Here's the output from that run:
    SQL> /
    output of the command run:
    init.ora
    initDBPart9i.DBPSun01.ora
    initdw.ora
    lkDBPART9I
    orapw
    orapwDBPart9i
    spfileDBPart9i.ora
    Done
    PL/SQL procedure successfully completed.
    But, I did need to change a line of your code to this:
    Process p = Runtime.getRuntime().exec("/usr/bin/ls");
    your original was:
    Process p = Runtime.getRuntime().exec("ls");
    You might consider, if possible, use of some of the Java File classes instead of ls, as this might make things more predictable for you. There were some examples in oramag.com a few months ago, but they were pretty simple (you might not need them).
    Hope this helps,
    -Dan
    http://www.compuware.com/products/devpartner/db/oracle_debug.htm
    Debug PL/SQL and Java in the Oracle Database

  • The CG$ASK_COMMIT alert is being generated from designer but from where??

    I am generating oracle forms from designer and the generated form contains an ALERT called CG$ASK_COMMIT. My question is, which generator property, specifies this ALERT?? I have looked everywhere? I am trying to change the alert type, style, wording without modifying the form after generation.
    Any help would be great.
    Thanks in advance,
    Terry

    I don't know if there is preference for it. What we do is put this in the when-new-form-instance:
         l_alert_id := FIND_ALERT('CG$ASK_COMMIT');
         IF NOT ID_NULL(l_alert_id) THEN
            SET_ALERT_PROPERTY(l_alert_id,ALERT_MESSAGE_TEXT,'<your message>');
            SET_ALERT_BUTTON_PROPERTY(l_alert_id, ALERT_BUTTON1, LABEL, '<your label>');
            SET_ALERT_BUTTON_PROPERTY(l_alert_id, ALERT_BUTTON2, LABEL, '<your label>');
            SET_ALERT_BUTTON_PROPERTY(l_alert_id, ALERT_BUTTON3, LABEL, '<your label>');
         END IF;

  • Installed BC InfoObject 'X' - Can not find it from RSA1, but from RSD1

    Hi all,
        I have installed the Business Content InfoObject 0ME_REVO_PA. I could find this InfoObject from RSD1 and it is active. I could see it in Business Content section also with Active status, but I can not find it from RSA1 under InfoObjects section. I have to find under which InfoObject Catalog it has been created.
        What could be the problem, please ?
       Thanks in advance.
    Regards.

    Hi Bhanu,
       As per Edwin Harpino's suggestion, ran function module (se37) RSDG_IOBC_REORG
    with following Import parameter :
    I_OBJVERS A
    I_PROGRESS
    I_IOBJTP *
    I_ALL_IOBJ X
    I_T_IOBJNM 0 entries
    I_BYPASS_BUFFER
       Now, I could see it in RSA1 also.
    Thanks.

  • I downloaded a mp3 not from iTunes but from lottery music store and the phone played them where did they go after that cause I can't find them?

    I downloaded two songs from the lottery music store onto my iPhone 3 and played part of both of them and now I don't know where to find them? Please help me

    Swipe your Home page to the far right and do a Search of your audio book.

  • Can i restore my iphone from icloud, but from a few months back?

    can i restore my iphone from icloud from a previous back up, running back to may?

    I believe only the most recent backup is saved in iCloud, if that's what you're asking.  If you haven't done an iCloud backup since May, then you could restore from it.  Otherwise, I believe it's been overwritten.
    Here's a good article about iCloud backup and restore:
    http://support.apple.com/kb/HT4859

  • OSB to Object Types: difference between NULL value and not available

    Hello all,
    I have a question about Object Types. More specifically, how to differentiate between an empty value (null) and a string not available.
    This is my case:
    I have created an object type with three parameters.
    CREATE OR REPLACE TYPE OSB_EMP_OBJ_TYPE AS OBJECT
    (EMP_ID NUMBER
    ,DEPT_ID NUMBER
    ,ORDER_ID NUMBER
    ,CONSTRUCTOR FUNCTION OSB_EMP_OBJ_TYPE
    RETURN self as result
    /I would like to see what happens when I put an empty string into emp_id, NULL into DEPT_ID and nothing into ORDER_ID.
    To do so I have this test script:
    declare
      p_emp OSB_EMP_OBJ_TYPE := OSB_EMP_OBJ_TYPE();
    begin
      p_emp.EMP_ID := '';
      p_emp.DEPT_ID := null;
    --  p_emp.ORDER_ID := null;
      if p_emp.EMP_ID is null
      then
        dbms_output.put_line('Empty');
      end if;
      if p_emp.DEPT_ID is null
      then
        dbms_output.put_line('NULL');
      end if;
      if p_emp.ORDER_ID is null
      then
        dbms_output.put_line('Not available');
      end if;
    end;The result of this is:
    Empty
    NULL
    Not availableIt seems that Oracle treats all three situations alike. What I would like to achieve is a way to see that p_emp.ORDER_ID was not initialized.
    To elaborate a bit: in our production system this procedure would be called from OSB and the object type would by the input for that procedure. Our database version is 10.2.0.5.0.
    Our procedures look something like this:
    procedure p_procedure ( p_emp in osb_emp_obj_type )
    is
    begin
      do_something;
    end;Can anyone tell me if there is a way to achieve this, so I can see whether or not a value in the object type was filled?
    Thanks in advance!

    Darn...
    Eventually we want to use this for an update procedure. The client gets all current data from the database by calling a webservice that (using OSB) selects the data from our database. What we want to achieve is that the client can update that data, by returning only the changed fields to an update procedure.
    We then handle an empty tag to update the field to null, and we ignore missing tags.
    OSB itself can handle this, but PL/SQL can't.
    I'm now thinking of adding an indicator to each optional field (clear_field_yn). OSB can still check for empty tags or missing tags. When a tag is empty, it's corresponding indicator will be set to 'Y'. If the tag is missing, then it will be set to 'N'.
    Is that a solution to consider, or is there a much simpler approach possible?

  • Nested Tables with Object Types

    Hi,
    Does someone know from which version on object Types can be referenced via database links ?
    I could not manage with Oracle 8.1.7 and needed this features as the only way to access
    a stored procedure array is via collection and using Object Types.
    But Object Types are not possible to access remotlely.
    Thanks in advance.
    brg robert

    Click on the link below and see if you can use that method as a way to work around the problem:
    http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:1252400357305

  • How to return Values from Oracle Object Type to Java Class Object

    Hello,
    i have created an Oracle Object Types in the Database. Then i created Java classes with "jpub" of these types. Here is an example of the type.
    CREATE OR REPLACE TYPE person_type AS OBJECT
    ID NUMBER,
    vorname VARCHAR2(30),
    nachname VARCHAR2(30),
    geburtstag DATE,
    CONSTRUCTOR FUNCTION person_type RETURN SELF AS RESULT,
    CONSTRUCTOR FUNCTION person_type(p_id NUMBER) RETURN SELF AS RESULT,
    CONSTRUCTOR FUNCTION person_type(p_vorname VARCHAR2,
    p_nachname VARCHAR2,
    p_geburtstag DATE) RETURN SELF AS RESULT,
    MEMBER FUNCTION object_exists(p_id NUMBER) RETURN BOOLEAN,
    MEMBER PROCEDURE load_object(p_id NUMBER),
    MEMBER PROCEDURE save_object,
    MEMBER PROCEDURE insert_object,
    MEMBER PROCEDURE update_object,
    MEMBER PROCEDURE delete_object
    MEMBER PROCEDURE load_object(p_id NUMBER) IS
    BEGIN
    SELECT p.id, p.vorname, p.nachname, p.geburtstag
    INTO SELF.ID, SELF.vorname, self.nachname, SELF.geburtstag
    FROM person p
    WHERE p.id = p_id;
    END;
    My problem is, that if i use the member function "load_object" from my java app it doesnt return the selected values to the java class and i dont know why. I use the java class like this:
    PersonObjectType p = new PersonObjectType();
    p.load_object(4);
    There is a reocrd in the database with id = 4 and the function will execute successful. But if i try to use "p.getVorname()" i always get "NULL". Can someone tell me how to do that?
    Thanks a lot.
    Edited by: NTbc on 13.07.2010 15:36
    Edited by: NTbc on 13.07.2010 15:36

    CallableStatement =
    "DECLARE
    a person_type;
    BEGIN
    a.load_object(4);
    ? := a;
    END;"
    And register as an out parameter.
    Edited by: michael76 on 14.07.2010 05:01

  • How to return object  type from external c procedure ?

    Hello all,
    I'm trying for the first time to return an object type as the return value of an external stored procedure (in C ).
    I don't have any issue to use an object type parameter for the function but not to return one to the caller.
    each time I try I get "ORA-03113: end-of-file on communication channel" and the connection is dropped.
    Thanks for any help,
    Roye Avidor
    here is the code :
    => object type
    SQL>create or replace type address as object ( age number, salary float );
    => address typ file
    CASE=SAME
    TYPE address as address
    => building the dependences structures.
    $>ott userid=scott/tiger intype=address.type code=c hfile=address.h
    => the package description
    create or replace package userTypeDefined_PKG
    is
    function getAddr( addr address ) return address;
    end;
    create or replace package body userTypeDefined_PKG
    is
    function getAddr( addr address ) return address
    AS LANGUAGE C
    NAME "addr"
    LIBRARY userTypeDefinedLib
    WITH CONTEXT
    PARAMETERS
    ( CONTEXT,
    addr,
    addr INDICATOR STRUCT ,
    return address,
    return INDICATOR STRUCT
    end;
    => The C code for the library in
    address* addr(OCIExtProcContext ctx, address address_obj, address_ind address_obj_ind, address_ind ret_ind){
    unsigned int tt;
    OCIEnv *envh;
    OCIError *errh;
    OCISvcCtx *svch;
    sword err;
    address* ret = NULL;
    int inum = 69;
    float fnum = 12.34;
    /* get OCI Environment */
    err = OCIExtProcGetEnv(ctx, &envh, &svch, &errh) ;
    /* allocate space for return sturcture*/
    ret = (address *)OCIExtProcAllocCallMemory(ctx, sizeof(address));
    /* set the AGE value */
    if ( OCINumberFromInt ( errh, &inum, sizeof(inum), OCI_NUMBER_SIGNED, &(ret->AGE) ) == OCI_ERROR )
    OCIExtProcRaiseExcp(ctx,(int)1476); // raise 1476 is fail
    /* set the SALARY value */
    if ( OCINumberFromReal ( errh, &fnum, sizeof(fnum), &(ret->SALARY) ) == OCI_ERROR )
    OCIExtProcRaiseExcp(ctx,(int)1477);// raise 1477 is fail
    // set the indicators for the structure as not null
    ret_ind->atomic = OCIIND_NOTNULL;
    ret_ind->AGE = OCI_IND_NOTNULL;
    ret_ind->SALARY = OCI_IND_NOTNULL;
    return (ret);
    }

    The return indicator should be declared as double pointer, and need to be allocated in the function body.

Maybe you are looking for