objectquery

QueryObject Include Entity Framework

Hi, I have three tables: Scenarios, Components and Blocks. Blocks has a foreign key to ComponentId and Components has a foreign key to Scenarios. Blocks also has a foreign key (TreeStructureId) to another table TreeStructures. Now, why does this work: ObjectQuery<Blocks> blocks = edumatic3Entities.Blocks.Include("TreeStructures").Inc...

Working with the ObjectQuery Single Enumeration Challenge in Linq-To-Entities Entity SQL

I'm working on modifying this example: Using advWorksContext As New AdventureWorksEntities ' Call the constructor that takes a command string and ObjectContext. Dim productQuery1 As New ObjectQuery(Of Product)("Product", advWorksContext) Dim result As Product For Each result In productQuery1 Console.WriteLine("P...

What happens when I'm casting an Linq to Entity query to ObjectQuery?

Hi, Simple question - what does this actually do? var oq = (ObjectQuery<TEntity>)L2EQuery; return ExecuteFirstorDefault<TEntity>(oq, MergeOption.AppendOnly); It's partly from the book Programming Entity Framework, by Julia Lerman. ...

Entity SQL compare datetime without milliseconds

I'm trying to fetch some records from MSSQL DB using EntityObject with EntitySQL query. The field i'm using to filter is type of datetime. The generated query projected without millisecond, to the SQL Server returns nothing. When i'm adding the milliseconds, i get results. How can i use the EntitySQL to get result without the millisecon...

ObjectQuery<T> without Entity Framework

How to use ObjectContext and ObjectQuery<T> with my own classes and objects? I.e. I don't want to use them with Entity Framework. How can I do this? ...

ObjectQuery, passing datetime in Where clause filter

How to pass in Date Time value here? ObjectQuery<Item> _Query = ItemEntities.CreateQuery<Item>("Item"); _Query = _Query.Where("(it.StartDate >= 11/4/2009 5:06:08 PM)"); my sample code above does seem to work. even with this ObjectQuery<Item> _Query = ItemEntities.CreateQuery<Item>("Item"); _Query = _Query.Where("(it.StartDate >= \"1...

Entity framework - ObjectQuery return int property and assign it to variable

Hi, I need to get UserCarId(int) from this query and assign to int type variable. int UserCarId; Entities ctx = new Entities(); var query = from enq in ctx.UserCars.Include("aspnet_Users") where enq.aspnet_Users.UserId == currentUserId select enq.UserCarId ; ...

How to query Entities in Entity Framework 4

In VS2008, I think it is EF1.0, this works just fine. string queryString = @"SELECT VALUE USERS FROM ProjectDBEntities.Users AS User INNER JOIN ProjectDBEntities.Favorites AS F ON F.FavUserId = User.UserId WHERE F.UserId = " + 3 + " ORDER BY F.CreateDate DESC "; System.Data.Objects.ObjectQuery<User> use...

Linq to Entites and ObjectQuery

Hi I have Person enity which has a 1 : N relationship with Person_Addresses (fields: PersonID, AddressID, ValidFrom). I want to get all Person records and associated Person_Addresses with only latest ValidFrom. How should i do this using ObjectQuery or IQueryable? Edit: I mentioned ObjectQuery and IQueryable because i wanted to have a ...

Can ObjectQuery.OrderBy() use NEWID() ??

Hi there, I found that Entity SQL support NEWID(), but does ObjectQuery support it as well? http://msdn.microsoft.com/en-us/library/bb738616.aspx, Can I write objectquery like: context.member.orderby("NEWID()").select("it.UserID"); or something like this? or I should write in other way? I thought if entity sql support NEWID() func...

How to execute an ObjectQuery<T>

Linq to Entities uses the ObjectQuery which implements IQueryable. I normally use the IQueryable methods to filter through my data but today I needed to create a special LIKE statement. The framework keeps thinking its smart and "escaping" my wildcard "%" with the tilde which rendered my special LIKE statement null and void. So after dig...

Entity Framework 4: Returning IQueryable or ObjectQuery when using LINQ to Entities?

Hi there, i have been reading when using Linq to entites a query is of type IQueryable before it is processed but when the query has been processed, it's no longer an IQueryable, but an ObjectQuery. In that case, is it correct to write methods from my layer (repository layer) to return IQueryable? Do i need to cast? Why would i want ...

How to use ObjectQuery with Where filter separated by OR clause

Hi guys, Could somebody help me to answer how to rewrite raw SQL filter WHERE (...) OR (...) with ObjectQuery bilder, please? String queryRaw = "SELECT ls.LocaleName, ls.IsActive, ls.LocaleDescription " + "FROM RoutesEntities.Locales AS ls "; //" WHERE ls.LocaleName = 'en' OR ls.LocaleName = 'de' " ...

Entity Framework - how to join tables without LINQ and with only string?

Hi all, I have a question about Entity Framework. Please answer if you know answer on this. I have such query : String queryRaw = "SELECT " + "p.ProductName AS ProductName " + "FROM ProductEntities.Products AS p " + "INNER JOIN CategoryEntities.Categories AS c " + "ON p.CategoryID = c.CategoryID "; ObjectQuery<Db...

Few GroupJoin in one query

Hi all, I'm trying to write ObjectQuery with few consistent GroupJoin, it means that there should be one main table selection + few additional LEFT JOIN. I'm doing it as following, with SelectMany method, because without it I can't access field RoleID : var routesQuery = entities.Routes.Join( entities.Locales, ...