how to join two tables in linq? Using WCF Data Service - asp.net

I want to join two tables in one of my linq query. I have written one code but it gives me an error like below
The method 'Join' is not supported.
I have tried this code:
var query = (from ls in this.testEntities.abc
join itm in this.testEntities.edf on ls.ID equals itm.ID
where itm.val == param
select new
{
ls.Name,
ls.Contact
}).ToList();
Am I missing something?
If anyone have any idea about it than please help me...

WCF Data Services is able to directly expand related objects based upon the Entity Data Model. (Don't worry about it if you don't know a lot about an EDM; it's not particularly important to the answer.) Since WCF Data Services is already aware, for instance, that a Product has a Category, I can fire up LinqPad, give it this URL, and issue a query like the following:
Products.Expand("Category").Take(2)
The result is two products, each with a property of type Category.
I'm not really sure what that translates to in the other LINQ syntax, sorry.
HTH,
Mark

Related

Find User IDs not on OPRDEFN in PeopleSoft FIN

Our former security admin team off-boarded terminated users by deleting their user profiles from the system. We have changed that policy but there is potential for duplicates. I am attempting to find user ids on the various module tables that are not on the OPRDEFN but having no luck.
I would like to query the major tables to return a list of all user ids to compare to the current OPRDEFN. From there, I can either have them added or create a reference list the admins to use prior to creating a new user id.
Does anyone have any tips or already written SQL? I am not the best SQL writer, I've tried several different things but nothings works.
Any help would be greatly appreciated.
Here you have a list of tables using the OPRID field. I have already formatted it in a way you can just run the result to get the Oprids.
Also, consider other columns like OPERATOR
SELECT 'SELECT DISTINCT OPRID FROM PS_'||RECNAME||';' FROM PSRECDEFN WHERE RECTYPE=0
AND RECNAME IN
(SELECT RECNAME FROM PSRECFIELD WHERE FIELDNAME IN ('OPRID','OPERATOR'))
AND RECNAME NOT LIKE '%AET'
AND RECNAME NOT LIKE '%TMP'
Also, you may just look at PSACCESSLOG, it will show you when someone access, so you may save time by querying it only

Dose any one know why post man is returning null values from fields that are not on my sql table?

So I'm pretty new to SQL and web API, but here goes... I have 4 tables in my database, 3 tables have foreign keys feeding into the other. I have been able display my data in postman. Although postman is giving me additional data fields with "null" entries at the bottom. These fields are not present in the table that I am fetching. Although they are present in my other tables.
here is how my data tables look
here is my Model - I think it may be because of these virtual classes in the model. If so how can I stop them being displayed for this particular HTTP get request.
i'm not really too sure whats going on with this
Sorry about the MASSIVE images, don't no what thats about :D any help would be greatly appreciated
Mark your properties with [JsonIgnore]:
[JsonIgnore]
public virtual TblModelName Name { get;...
To prevent it being serialized. I believe that this attribute works for both NewtonSoft.Json and System.Text.Json
Try removing [] array paranthesis and simply put in {} curly brackets it will take values as you enter from postman via post request.

How to get column wise data using AEM query SQL2?

I am running a following AEM Query SQL2 on CRXDE and it is successfully returning me nodes as per following given screenshot.
But I need data like column wise (jcr properties) like SQL table. Can anyone help me if it is possible.
You can't do this with CRXDE. It shows only the path of the most outer node, even if the query has multiple columns. This is especially limiting, if your query uses joins.
In your case I would recommend the Query Builder. It has a totally different syntax, but the JSON or XML result contains all data you need.
I don't know other tools. As AEM developer I usually write a quick & dirty servlet, and let it run on my local instance (with production content)
Query Builder Debugger
http://localhost:4502/libs/cq/search/content/querydebug.html
Example Query
path=/content/we-retail/language-masters/en/experience
property=sling:resourceType
property.value=weretail/components/content/image
p.hits=full
p.nodedepth=2
Resulting JSON Query
http://localhost:4502/bin/querybuilder.json?p.hits=full&p.nodedepth=2&path=%2fcontent%2fwe-retail%2flanguage-masters%2fen%2fexperience&property=sling%3aresourceType&property.value=weretail%2fcomponents%2fcontent%2fimage
http://localhost:4502/bin/querybuilder.json?p.hits=full&p.nodedepth=2&path=%2fcontent%2fwe-retail%2flanguage-masters%2fen%2fexperience&property=sling%3aresourceType&property.value=weretail%2fcomponents%2fcontent%2fimage
Documentation
https://docs.adobe.com/content/help/en/experience-manager-64/developing/platform/query-builder/querybuilder-api.html
In your case especially see: Refining What Is Returned
You will find much more with Google, as the Query Builder is pretty old in AEM/CQ.

Is this the correct way to add conditions using LINQ (for database queries)? [duplicate]

This question already has answers here:
Multiple .Where() clauses on an Entity Framework Queryable
(2 answers)
Closed 4 years ago.
I have some dynamic conditions that I want to use in my Select clause.
So I would like to create a "base query" like "SELECT * FROM TABLE" and after I wuold like to add conditions like "WHERE name = 'Diego' AND ...".
I'm using Entity Core, and the solution I found (it's working) is as follows:
//conditions
Expression<Func<Person, bool>> foo = (p => p.Id == 1);
//select
List<Person> people = Db.People.Where(foo).ToList();
//Db is the context, People is the DbSet and Person is the model
I hope there is a simple or standard way to do that, in fact I have tried some, but they haven't worked.
Anyway where can I find a good tutorial about it, from simple to complex?
---------------------- UPDATE -----------------------------
Well, this question has marked as duplicate, but this Multiple .Where() clauses on an Entity Framework Queryable , doesn't worked for me,I don't know why, but the statement executes before the conditions, (if I do the same thing like the answer on the link), and I want to apply the conditions before the first statement execution. Yes I know I must use toList() just at the end, anyway if I do the same thing like the answer on that link, the statement will execute before, and I agree this is very strange.
---------------------- UPDATE -----------------------------
I provide some kind of proof for what I'm talking about in the images below:
Here we have a single statement execution (the result is a single Person object), in this example I'm using the code I've written above.
Here as we can see, the code: queryable = Db.People.Where(p => p.Name.Contains("El"));, is executed (the result is two Person objects), even without the method
ToList(), in this example I'm using the suggested code.
Well maybe it's a entity core bug.
Anyway this question is not the same of that which was been linked for many reasons.
Here as we can see, the code: queryable = Db.People.Where(p => p.Name.Contains("El"));, is executed (the result is two Person objects), even without the method ToList(), in this example I'm using the suggested code.
Sorry but what you are seeing is the fact that you accepted allowing the expression to run. It did NOT run until you opened the results as stated in your own screenshot:
So this is a duplicate, you are just unfamiliar with how the locals/watch windows work.

Linq to SQL Design question

Often I need to combine data from multiple tables and display the result in a GridView control.
I can write a Linq query inline in the Page_load event, return an anonymous type that combines all the fields that I need, and databind the result to the GridView control.
Problem: I use 'helper methods' as described by Scott Guthrie on his blog. Such a helper method cannot return an anonymous type. The query would have to be inline for this approach.
I can write a database view that returns the data that I need, and write a helper method with a query against this (new and known) type that it returns.
Problem: I will need a lot of views in my database schema, and I will introduce a lot of redundant aspects of my data. I also lose some of the advantage of using Linq - removing all business logic from the database.
I would like to take an approach that lets me keep the Linq queries in helper methods, yet allows me to access all the attributes that I need on the grid in their respective databinding expressions. Can this be done?
I asked the wrong question, as I frequently do. What prompted me to look into anonymous types was an apparent limitation of the GridView - my inability to use a databinding expression in an <asp:BoundField> (the DataField parameter only accepts column names of the table that the Linq query pulls in).
Turns out that in a TemplateField it is possible to use Eval and access members of the Linq data item, and Linq takes care of the query for me.
In other words, I can keep the query in my helper method, have it return a primary database table type (e.g. Account), and I bind the Accounts to the GridView.
In the databinding expressions I can access data members of the Account objects that reside in other tables, without having to explicitly pull them in in the query. Perfect.
I don't know if there is a viable way to achieve this using anonymous types. But I have a suggestion that will work in WinForms, but I am not sure about ASP.NET.
What you need is a type with properties where neither the number of properties, nor the types and names of the properties are known at compile time. One way to create such a thing is ICustomTypeDescriptor.
You have to create a type implementing this interface with an private backing store of objects backing the properties returned by the query for one row from the query. Then you implement GetProperties() to return one PropertyDescriptor per column and PropertyDescriptor.GetValue() and PropertyDescriptor.SetValue() to access the backing array.
By implementing PropertyDescriptor.Name you will get the correct column name; this will probably require another backing store storing the property names. And there is a lot more to implement, but in the end your new type will behave almost like a normal type - and now the if - if the control you are binding to knows about and uses ICustomTypeDescriptor.
UPDATE
I just found an bit of text stating that ASP.NET data binding knows and uses ICustomTypeDescriptor.
Scott's earlier post in the series talks about shaping the result set before inserting into a grid:
Part 3 - Querying our Database
Scroll down to "Shaping our Query Results".

Resources