named native query and mapping columns to field of entity that doesn't exist in table


Taylon Silmer
HOME ยป Development Tools & Services

I have a named native query and I am trying to map it to the return results of the named native query. There is a field that I want to add to my entity that doesn't exist in the table, but it will exist in the return result of the query. I guess this would be the same with a stored proc...


How do you map the return results of a stored proc in JPA?...


How do you even call a stored proc?


here is an example query of what I would like to do...


select d.list_id as LIST_ID, 0 as Parent_ID, d.description from EPCD13.distribution_list d

The Result will be mapped to this entity...

medianet_width='336'; medianet_height= '280'; medianet_crid='202258688';

Related to : named native query and mapping columns to field of entity that doesn't exist in table
named native query and mapping columns to field of entity that doesn't exist in table
Development Tools & Services

I have a named native query and I am trying to map it to the return results of the named native query. There is a field that I want to add to my entity that doesn't exist in the table, but it will exist in the return result of the query. I guess this would be the same with a stored proc...


How do you map the return results of a stored proc in JPA?...


How do you even call a stored proc?


here is an example query of what I would like to do...


select d.list_id as LIST_ID, 0 as Parent_ID, d.description from EPCD13.distribution_list d

The Result will be mapped to this entity...

Using a named native sql query using xml mapping error
Development Tools & Services

I'm using a named native SQL query using xml mapping, I need to use the mysql function AES_ENCRYPT and AES_DECRYPT but marked me syntax error but do not understand why. Now review it all and is wellI'm using a blob field to store the encrypted data of AES_ENCRYPTUsuario.hbm.xml<?xml version="1.0"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN""http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"><!-- Generated 14/12/2013 03:41:41 AM by
columns named as table.field instead of field
Development Tools & Services


I'm selecting from various tables and fields with the same name in various tables get mixed... Is it possible to make a query so the names of the columns that is returned are named like table.field and not just field, that is, using the name of the table and not just the name of the field.
In fact, my example is a bit more complex, I have to tables, table1 and table2 which have a static structure (never changes) and two other table that have a structure that might change, let's call them table3 and table4.
I'm doing a select where I get table1.id, table2.name, table3.description and I'd like to select table3 and table4 to be named extra.fiel
Entity framework is trying to use a table that doesn't exist in the SQL for a navigation property
27/11/2014 10:20 am Development Tools & Services

In my C# application (an ASP.NET MVC5 website) I am using Entity Framework 6 as my ORM and I'm using code-first with an existing database. The database is SQL Server 2012 Standard.

In my database I have a view (dbo.vBoardReportLayouts) that functions as a joining table for a number of different elements. I've created an entity for this view and configured the navigation properties.

When I attempt to use this entity with LINQ entity framework generates a SQL query that tries to use a table that doesn't actually exist. Specifically it is looking for the BoardReportLayoutPages table.


Now for all the gory details...

The vBoardReportLayouts view looks like this:

| ReportID | PageTypeId | PageId | LayoutID |
+----------+------------+--------+----------+
| 1        | 1          | 1      | 1        |
| 1        | 1          | 1      | 2        |
| 1        | 1          | 2      | 3        |
| 1        | 1          | 3      | 4        |
| 1        | 2          | 4      | 5        |
| 1        | 2          | 4      | 6        |
| 2        | 1          | 1      | 1        |
| 2        | 1          | 1      | 2        |
| 2        | 1          | 2      | 3        |
| 2        | 1          | 3      | 4        |
| 2        | 2          | 4      | 5        |
| 2        | 2          | 4      | 6        |

The BoardReportLayouts entity class:

[Table("vBoardReportLayouts")]
public partial class BoardReportLayout {
    public BoardReportLayout() {
        BoardReports = new HashSet<BoardReport>();
        PageTypes = new HashSet<PageType>();
        Pages = new HashSet<Page>();
        PageLayouts = new HashSet<PageLayout>();
    }

    [Key]
    public int BoardReportLayoutId { get; set; }

    public int BoardReportId { get; set; }

    public int PageTypeId { get; set; }

    public int PageId { get; set; }

    public int PageLayoutId { get; set; }

    public virtual ICollection<BoardReport> BoardReports { get;
set; }
    public virtual ICollection<PageType> PageTypes { get; set; }
    public virtual ICollection<Page> Pages { get; set; }
    public virtual ICollection<PageLayout> PageLayouts { get;
set; }
}

From the OnModelCreating() method of the dbContext:

modelBuilder.Entity<BoardReportLayout>()
    .HasMany(e => e.BoardReports)
    .WithMany(e => e.BoardReportLayouts);

modelBuilder.Entity<BoardReportLayout>()
    .HasMany(e => e.PageTypes)
    .WithMany(e => e.BoardReportLayouts);

modelBuilder.Entity<BoardReportLayout>()
    .HasMany(e => e.Pages)
    .WithMany(e => e.BoardReportLayouts);

modelBuilder.Entity<BoardReportLayout>()
    .HasMany(e => e.PageLayouts)
    .WithMany(e => e.BoardReportLayouts);

The BoardReport, PageType, Page, and PageLayout entities all have the following property defined:

public virtual ICollection<BoardReportLayout>
BoardReportLayouts { get; set; }

Executing this LINQ query:

var test = (from l in ppdb.BoardReportLayouts
            where l.BoardReportId == 8
            select l.Pages).SelectMany(p => p).ToList();

Generates this SQL:

SELECT [Join1].[PageId] AS [PageId], 
    [Join1].[PageTypeId] AS [PageTypeId], 
    [Join1].[Name] AS [Name], 
    [Join1].[ParameterValue] AS [ParameterValue], 
    [Join1].[SsrsPageParamterValue] AS [SsrsPageParamterValue], 
    [Join1].[TableOfContentsOrder] AS [TableOfContentsOrder]
    FROM  [dbo].[vBoardReportLayouts] AS [Extent1]
    INNER JOIN  (
    SELECT [Extent2].[BoardReportLayout_BoardReportLayoutId] AS
[BoardReportLayout_BoardReportLayoutId],
        [Extent3].[PageId] AS [PageId],
        [Extent3].[PageTypeId] AS [PageTypeId],
        [Extent3].[Name] AS [Name],
        [Extent3].[ParameterValue] AS [ParameterValue],
        [Extent3].[SsrsPageParamterValue] AS [SsrsPageParamterValue],
        [Extent3].[TableOfContentsOrder] AS [TableOfContentsOrder]
        FROM  [dbo].[BoardReportLayoutPages] AS [Extent2]
        INNER JOIN [dbo].[Pages] AS [Extent3] ON [Extent3].[PageId] =
[Extent2].[Page_PageId]
    ) AS [Join1] ON [Extent1].[BoardReportLayoutId] =
[Join1].[BoardReportLayout_BoardReportLayoutId]
    WHERE 8 = [Extent1].[BoardReportId]

The problem is in the FROM clause of the [Join1] table expression. I'm not sure why it is trying to use the table dbo.BoardReportLayoutPages since it could join directly from the view to the Pages table. The table dbo.BoardReportLayoutPages doesn't exist so this throws an exception.




HD Wallpapers
3D
3D Abstract
City
Celebrities
Indian Celebrities
Cars
Travel
Girls
Animals Birds
Movies
Sports
Black White
Nature
Planes
Anime
Food Drink
Dreamy Fantasy
Architecture
Games
Space
Holidays
Flowers
Love
Artistic
Baby
Beach
Bikes Motorcycles
Macro
Computers
Vector
Funny
Army
Textures
Brands
Misc
Music
Other
Privacy Policy - Copyrights Notice - Feedback - Report Violation - RSS 2017 © bighow.org All Rights Reserved .