Is it possible to use column alias in odata select? - select

I'm trying to get the data from a column with the name "contactName", and i want the results to show as "Name".
Is this possible in odata select?

One possible solution is to bind your DBContext to a SQL View instead of the table. In the SQL view create your Alias.

Related

Entity Framework query based on string stored in configuration file

i would like to know if you have any idea how i can achieve this, considering a query stored as string in the configuration file.
I tried to use SqlQuery applied to the DBSet, but the problem is that SqlQuery requires me to select all properties of the required entities in my query. If i don't consider any column, it will complain because is not able to map the query to the entities.
I don't want to select all properties of the entities i want to query.
Thanks
If you are using EF then why not use Database.ExecuteSqlCommand()? It's in the System.Data.Entity namespace.
For example:
int result = db.Database.ExecuteSqlCommand("Non SELECT SQL etc...");
Well, I ended up implementing a mechanism using reflection that basically receives a group of fields to select, and constructs dynamic objects with those fields, so when applied the query with the joins between the entities, will only bring the fields I am looking for.
So, considering Entity1, Entity2, Entity3 with the following relationship
<b>Entity1</b>{
<br/> Entity1Name, <br/> List<*Entity2*> Entity2Items, <br/> etc..
<br/>}
and
<b>Entity2</b> { <br/> Entity2Name, <br/> List<*Entity3*> Entity3Items <br/>}
I can store e.g. the following query in the configuration file, and retrieve the information:
"Entity1.Entity1Name", <br/>
"Entity1.Entity2Items.Entity2Name", <br/>
"Entity1.Entity2Items.Entity3Items.Entity3Name"
Anyway, I was just trying to see if there would be any solution out-of-the-box that would require minimal code changes.
Thank you.

JPA: Map a group of table columns extracted by native query to entity

I know that it is possible using #SqlResultSetMapping but I want to select not whole entity from the database but some fields and then map i to my entity using one of the constructor which accept that fields. Is that possible to map result with #EntityResult for only a few #FieldResult? I was trying to do that and all the time I get error which said that there is not specify mapping for some fields which exist in that entity.
The disadvantage of #SqlResultSetMapping is that you have to select all the columns.
The alternate way of doing this manually iterate over the DB result and populate your objects.
Well, if you are using JPA 1.0 your only option (not considering the manual mapping, of course), is to use #SqlResultSetMapping and map the whole table columns. With JPA 2.1 you can add a javax.persistence.ConstructorResult (see docs here) to map only the needed columns.

How to use Entity framework to pass Table Valued parameter to Stored procedure

I have tables with 2 level hierarchy, Parent->Child->GrandChild
I have create stored procedure with three table valued input parameter ParentTable, ChildTable, GrandChild Table.
Now, I want to consume it in .net using entity framework.
Solution all over internet is, create DataTable in .net , store data in it and pass the same as parameter in stored procedure.
But, I want to use entities instead of data table as data is stored in entity objects. Please suggest. Many Thanks.
You need to have look at this question
Create data table from entities and then pass it to the stored procedure. I haven't tried the code, just showing you the path to go. I hope it may help, looking for better solution.

Spring repository query to return a map with day as key

Having an entity that contains a column named "workDay" how can I make query to get all entries in a map where key is "workDay" and value a list of entities.
Any hing is welcome.
Thanks.
You want a query method to return Map<Date, List<?>>. Map is not a supported return type for query methods. Therefore, you cannot use the default implementation to achieve what you are looking for.
You can create a custom repository implementation that queries the database and returns the desired Map<Date, List<?>>.

Using Stored Procedure to populate dropdown box using Entity Framework

I am using MS Entity Model to attach to my db, and everything has worked fine. But I have a stored proc that returns a list that has two columns (one int and one text column) and I am trying to bind to a dropdownbox. The examples seem to show returning a single column or returning a data type of one of the tables. But my stored proc returns the values from various tables. Can someone point me in the right direction.
Thanks
In EF v1 you can only map a stored proc to an entity type.
In EF v4 you can map a stored proc to an entity type or a complex type.
So the solution will vary depending on which version of EF you use.
If you are using MVC once u have list bind it to the view using SelectList
some thing like this
<%: Html.DropDownListFor( c => c.Movie.LanguageId,
new SelectList((IEnumerable)Model.LanguageList, "LanguageId", "Name", null))%>