The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

table owners? how to work around them in entity spaces

Last post 08-28-2008, 12:19 AM by David.Parsons. 9 replies.
Sort Posts: Previous Next
  •  08-27-2008, 7:42 AM 10965

    table owners? how to work around them in entity spaces

    I've gone through a lot of problems while working in this project, and recently realized what the problem was. I made tbe custom and generated classes for the table called "factura". However, factura has various owners, so there's like, 4 tables called factura with different owners.
     
    So i'm assuming that's the problem and the reason why I can't do anything on my project. The exception thrown is:
     
    "Invalid name "Factura""
     
    The exception is thrown by a simple "col_fact.loadAll();" where col_fact is a FacturaCollection. The specific table i'm trying to access is named "mayorpit.Factura". Any ideas on how to work around this? Any help would be greatly appreciated :D
  •  08-27-2008, 9:25 AM 10966 in reply to 10965

    Re: table owners? how to work around them in entity spaces

    Ahh, schemas. We don't run into that often but here's what you might try.

    When you generate your code if you make sure to have the ignore schema/catalog checkboxes checked then your user id you use in your connection should have access to the right table, but still, I think there would be issues. How do you plan to indicated what schema to use (I usually avoid schemas but that's another issue).


    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  08-27-2008, 9:36 AM 10967 in reply to 10966

    Re: table owners? how to work around them in entity spaces

    Well, the database is not mine. I'm at work and I'm supposed to update one of their old system that works with visual 6 and a normal database connection, and I'm optimizing it in .NET and adding the entity spaces objects for easier management of the tables. (I'm creating the program from the start again).
     
    Those checkboxes are checked, and I think I have an advantage to my own ; there's a table called "facturas" and there's five owners for them. So there's five tables called factura, so I just want to access to the one owned by mayorpit. The advantage is, all the tables are exactly the same, i mean, they have the same fields, but the records are different obviously.
     
    In myGeneration, it only shows one table called "factura" , and no owners. So i'm assuming that i could use that object to do a select to mayorpit.factura, since they use the same fields and all.
     
    Is there any possible way to use a dynamic query from clause in this? like
     
    col_fact.Query.From("mayorpit.factura");
     
    I've tried it, but the paramater has to be a From object, and I've no idea what that is. =3
     
    Any ideas?
  •  08-27-2008, 9:56 AM 10968 in reply to 10967

    Re: table owners? how to work around them in entity spaces

    Ha ! You just made me think of something, try this:

    col_fact.Query.es.QuerySource = "mayorpit.factura";

    Then do everything else as normal.


    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  08-27-2008, 10:09 AM 10971 in reply to 10968

    Re: table owners? how to work around them in entity spaces

    Well, looks like it should work. But it still says: "Invalid object name 'MAYORPIT.FACTURA'." Probably has something todo with the myGeneration objects??? Also, the table name is correctly written.
  •  08-27-2008, 10:32 AM 10972 in reply to 10971

    Re: table owners? how to work around them in entity spaces

    Do a try catch and capture the Query.es.LastQuery and see what the SQL looks like.
    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  08-27-2008, 10:41 AM 10973 in reply to 10972

    Re: table owners? how to work around them in entity spaces

    "SELECT * FROM [MAYORPIT.FACTURA]" looks good to me. :3
  •  08-27-2008, 10:48 AM 10975 in reply to 10973

    Re: table owners? how to work around them in entity spaces

    I would try it in query analyzer, it should work, then use whatever is correct as your query source
    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  08-27-2008, 10:53 AM 10976 in reply to 10975

    Re: table owners? how to work around them in entity spaces

    It does indeed work in the query analizer, I'm connect to a remote server though. And the connection string is ok. It takes quite some time to load all the records in the query analizer, but it does load them. Altough from C# it just says "Invalid object".
  •  08-28-2008, 12:19 AM 10989 in reply to 10976

    Re: table owners? how to work around them in entity spaces

    This should get the same "Invalid object name" in Management Studio as it does from the app:

    Code:
    SELECT * FROM [MAYORPIT.FACTURA]

    Assuming the "Initial Catalog" is set to the database in your connection string, the correct syntax for schema and table is:

    Code:
    SELECT * FROM [MAYORPIT].[FACTURA]

    To accomplish this in EntitySpaces, regenerate your Generated Master. Check "Use Custom Base Class" on the advanced tab. Add the three files in this folder to your VS project:

    C:\Program Files\EntitySpaces 2008\CodeGeneration\CustomBase\C#

    Open CollectionBase.cs and add this method:

    Code:
    public void SetSchema(string schemaName)
    {
        esProviderSpecificMetadata spec = 
            this.Meta.GetProviderMetadata("esDefault");
        spec.Schema = schemaName;
    }

    Usage examples based on AdventureWorks:

    Code:
    EmployeeCollection emps = new EmployeeCollection();
    emps.SetSchema("HumanResources");
    emps.LoadAll();
    
    CustomerCollection custs = new CustomerCollection();
    custs.SetSchema("Sales");
    custs.LoadAll();

    David Neal Parsons
    www.entityspaces.net
View as RSS news feed in XML