Convert Iqueryable to DataTable - c#-3.0

I am using Linq-To-Sql, how do I convert an Iqueryable type to DataTable type. I could not find any method call in the framework that did it for me.

Technically you could just loop through your results and insert them into a DataTable as shown here, but why would you want to?

This might be a more efficient approach: Creating a DataTable From a Query (LINQ to DataSet): http://msdn.microsoft.com/en-us/library/bb386921.aspx

Related

Get Resultset from MyBatis

I have an application that uses myBatis.
I do not want to convert the resultset from mybatis to a Java object. So essentially I do not want a mapped object. I just want the resultset.
Is it possible to get that from myBatis?
Something like:
Resultset resultset = mybatisMapper.getResults();
I already have a program which processes this Resultset and I cannot change that program.
If you don't want a mapped object as result of your query you don't have to use a mapper. Try to take a look to this link, I think it can be useful for you:
Ibatis/MyBatis select dynamically without need to create any Pojo / Mapper

Handling multiple tables using List<> in MVC

Here is my prob, am new to mvc,
I have used a List<> to get Data from Store Procedure as below,
List<Sp_MM_GetDetails_Result> lDetails = objDB.Sp_MM_GetDetails(ArticleURL).ToList();
Its working fine for me, but my SP returning 2 table of data. However my List<> taking only first table's data.
what should do if I wanted to get data from second table?
In C#, we can done this by using
DataSet.Table[1]
You need to execute the raw SqlCommand and execute Translate to map to the matching types.
Check this sample
https://msdn.microsoft.com/de-de/data/jj691402

How to pass a function (or expression) into the where clause of an Entity Framework Query

I'm getting errors when I try and do something like this:
from s in db.SomeDbSet where IsValid(s) select s
It errors telling me that it can't process IsValid.
Basically what I'm trying to do is filter based on another dbSet inside the Where that is linked and does an any, but it won't let me.
I've tried a million different ways of doing a Expression but I can't find the right way and building my own Extension method like Where doesn't seem to work either.
Thanks!
Can you paste your IsValid function?
In this case it's EF job to take LINQ syntax and turn it into SQL syntax.
EF can't turn your function into SQL. it only supports a set number of functions that have a clear SQL equivalent commend.
you have two options:
1) Rewrite the function as a series of supported commends. This will be turned into a SQL sub-query, Meaning a single trip to the database, For example:
// will only return records that have at least one related entity marked as full.
query.Where(m => m.ReletedEntities.Any(re => re.IsFull == true));
2) Get all the data from the database and then using Linq and your function work with the data. this will be done in memory using your actual function that will be called once for every item in the collection. You will also have to load the related entity collection. or it will still be an "entity framework translated to SQL query", And will fail if you use your function.

How to execute a raw sql query from LINQ to Entities 4.5?

Problem
I need to execute a raw SQL query from LINQ to Entities and retrieve the result. The query returns the current date/time from the SQL Server instance, and looks like this:
SELECT GETDATE()
[Edit]
I'm using a data model that was created database-first.
[/Edit]
What I've Tried
I've researched this issue on the interwebz and been unable to find a technique to do this. I was able to learn how to do this using LINQ to SQL, but since I'm not using that, it's of no help.
Heres what you are after
var time = context.Database.SqlQuery<DateTime>("SELECT GETDATE()").FirstOrDefault();
You can read more about raw sql and EF here http://msdn.microsoft.com/en-us/data/jj592907.aspx

Is there a limit to the number of DataColumns I can add to a DataTable?

I can't find any references to there being a limit to the number of DataColumns I can add to a DataTable. The DataTable will not be generated from a SQL query, but rather synthesized from other data.
Thanks,
Matthew
The Method signatures for AddAt and RemoveAt and Item for the DataColumnCollection class all take Int32. This is the object that the DataTable Class uses to store the columns.
This means it can have 2,147,483,647 columns give or take 1 or 2 for good measure. :)