.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

How to setup Query Result Shaping for LinQ to SQL instead of Entity Framework?

Posted By:      Posted Date: September 10, 2010    Points: 0   Category :ASP.Net
Hi, I am new to this, and I am trying to implement a linq query similar to db.Genres.Include("Albums") command from mvc music store using my current DB setup. I realize that the tutorial mentions Checlking the "Include foreign key columns in the method" when creating the tables in ADO.NET, but if I am using LINQ to SQL classes, then how can I obtain the same effect. And how do I use db.Genres.Include("Albums") to simplify my life? Thanks

View Complete Post

More Related Resource Links

SOA Data Access: Flexible Data Access With LINQ To SQL And The Entity Framework


Building a data access layer using LINQ to SQL and the ADO.NET Entity Framework allows you to decouple your application from the persistence technology you're using.

Anthony Sneed

MSDN Magazine December 2008

Net Framework 1.0 Error 1904 during setup mscoree.dll H-result 2146232576

I cleaned off all my .Net framework files with the .Net framework cleaner. I then started at 3.5, installed it, went well, installed 3.0, went well, installed 2.0, went well, installed 1.1, went well, then, tried to install 1.0 redistribution package for my windows xp home and it stopped at almost the very end saying ERROR installing 1.0 ERROR 1904 system32\mscoree.dll failed to register. H-result 2146232576. I tried renaming it and installing the 1.0 again but still get the same error. i tried using the IGNORE option, it said it installed but i know the mscoree.dll isn't working. i used the installer cleanup tool also to no avail. i deleted the URTTemp folder and tried a reinstall. This didn't work either. Anyone know what I might can do to get this corrected? I have not done anything myself in the registry. I have used RegCure and registry mechanic but Net Framework 1.0 still gave the error when I tried to install. Any help appreciated. I did read something about 1.1, 2.0,3.0 or 3.5 might have a newer mscoree.dll file and that night be why I can't register the one I have. I need the 1.0 version 3705 though as one of my programs uses it. Also, i am now not able to put any of the updates on my computer. it downloads them but they fail to install. Example, net framework 2.o service pack 2, net framework 3.5 service pack 1, and net framework 3.5 family update. Thanks....

Dynamic Class with Linq query Result

Hi, var   query = db.Customers.Where( "City == @0 and Orders.Count >= @1", "London", 10). OrderBy( "CompanyName"). Select( "New(CompanyName as Name, Phone)");    I am using this query as a sample which returns a dynamicclass type, and i need this should to converted to a list collections or datatable etc., As i am holding it in my wcf service with linqtosql as dataaccesslayer. Trying to send the results to the UI which i have consumes this service. Kindly help me in this. Thanks query = db.Customers

Need to add hard coded values to LINQ query result

I am running a LINQ query which populates a list used by a DropDownList, I need to insert an "Unassigned" value to the list. The function below queries the values correctly from the db but does not insert the "Unaasinged" value to the list. Please help.   public List<KeyValuePair<int, string>> GetTestList() { KeyValuePair<int, string> item = new KeyValuePair<int, string>(0, "Unassigned"); using (DataClassesDataContext db = new DataClassesDataContext()) { var Query = from records in db.TEST_SUITEs orderby records.TEST_SUITE_ID select new KeyValuePair<int, string> ( records.TEST_SUITE_ID, string.Format(records.TEST_SUITE_ID + " " + records.SUITE_TYPE + " " + records.SUITE_NAME) ); //Query.ToList().Insert(0, item); Query.ToList().Insert(0,item); return Query.ToList(); } }  

VS 2010: no Entity Framework or LINQ support for SQL Server 2000 SQLOLEDB connection?

Hello, I'm working with Visual Studio 2010 and for Data Connections am connecting to a SQL Server 2000 production database. When I try to drag a table to a .dbml file, the Object Relational Designer says, "The selected object(s) use an unsupported data provider."If I try to create an .edmx file via Generate from database, then the alert is, "This server version is not supported. You must have Microsoft SQL Server 2005 or later."So VS 2010 has no support for the Data Entity Framework or LINQ when connecting to a SQL Server 2000 database? If that is the case, what is the best data access strategy for this scenario?  

Check if Linq query return result

HelloI have Linq query likeDim Prood= (From p InProdutcts _                                          where p.ProductID="InputInteger"                                                         ..... ) .SingleOrDefaultI could Use Count if I Use .ToList Instead of .SingleOrDefault , But now that I use 'SingleOrDefault', how Could I find if Prod contains any record or it's Empty.

When to use views and sp with linq entity framework?

Hi, When do I need (/ best practice) to use views and stored procedures in my database when using linq with the entity framework?Can you give me example scenario's? Thanks!

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<DbDataRecord> query = new ObjectQuery<DbDataRecord>(queryRaw, entityContext);
    GridView1.DataSource = query;

Particularly I want to join few tables in one query, but I can NOT use LINQ and can NOT use ObjectQuery with objects mapped to DB fields inside my query. Because each entity creates dynamically. So this is what i can NOT use :



The question is can I use something like this instead of using objects?

query.Join ("INNER JOIN CategoryEntities.Category ON p.CategoryID = c.CategoryID ");

Is there a way to query entity based on multiple filter criteria? WCF Data Services, Linq to Entiti


Instead of:

DW_CMSOPEN dwc = new DW_CMSOPEN(new Uri("http://acctdev02/WCFDataService/EmployeeService.svc"));

dwc.Credentials = System.Net.CredentialCache.DefaultCredentials;

var employees = from emp in dwc.Employees 
             where emp.DEPT == "123"
             select emp;

I'd like the linq query to resemble:

var employees = from emp in dwc.Employees
              where emp.DEPT // in {"123", "456", etc}
              select emp;

Entity Framework vs LINQ to SQL


what is diffrence between

Entity Framework and LINQ to SQL

i cant yet find a good  blog on this

i have read that in LINQ to SQL only one to one mapping is possible

but Entity Framework allowes many , is it right? if so i dont understand this

data shaping question - can this much conditional processing can be done within the linq query?



I have a scenario where I need to map the value of a field to a different value... easier explained with simple example:

when actual field data is "RED" I need to return "some other data"
when actual field data is "BLUE" I need to return "something else" 

so I've written linq to sql statements that project and shape, but I've never had to include any 'conditional' processing, can you?

Entity Framework - How to Query Based on Relationships


I have the following related tables:











User (FK - Users: Id)

Status (FK - UserStatuses: Id)


As you can see, UserStatuses is a reference table with various statuses. Users_UserStatus is a join table between Users and UserStatuses. Using Entity Framework, how can I do a conditional to check if the latest StatusDate is "Pending"? As of now, I have the following:

            Dim user As User = rep.Users.FirstOrDefault(Function(x) x.Username = userName)
            If user Is Nothing Then
                Return False
                Dim hashedPassword As String = Helpers.Security.CreatePasswordHash(password, user.PasswordSalt)
                If hashedPassword = user.Password Then
                    Return True
                    Return False
                End If
            End If


Entity framework "in" query


Entity framework "in" query

I need a query that I didn't success write using the EF

I need check if (is admin)
That gets all rows
Otherwise get only the project that connected to this user

If I should write this query in sql I write:
select * from dbo.TimeToWork
where TimeToWorkId in(select TimeToWorkId from dbo.TimeToWorkToUser where userid = @UserId)

I try wirte this query in EF with no impressive results
  public List<TimeToWork> GetAll(int UserId, bool IsAdmin)
            var timeToWorkcoll = (from timeToWorks in _context.TimeToWork

[Entity framework] Strange error executing a sql query


Hello to all,

I have a strange error, I've tried to search for it before writing this post but I wasn't able to find out a solution yet.

I'm executing a query using ExecuteStoreQuery against a MySQL database, but it throws an exception reporting that there's a syntax error in my SQL.

I've tried to copy&paste the sql query into the MySQL tool and it works nicely, giving the correct results.

I've tried to open manually the connection and using CreateCommand to use it the "old way".

My query is a bit long, 4000 chars more or less, could it be the problem?

Thank you very much!


Multiple database support with Entity Framework

One of the features introduced in Entity Framework is being database independent. Which mean each database provider can support Entity Framework by implementing its provider.

This feature allows you build applications independent from the underplaying database provider. In this post I'm going to show how to build an application that support multiple databases using same conceptual model made by Entity Framework.

Creating a Generic Entity Framework 4.0 Repository

With .NET 4.0 right around the corner, I thought it would be cool to download Visual Studio 2010 beta 2 and start playing around with the next release of Entity Framework.

The initial release of Entity Framework came with a great deal of criticism. To make matters worse, there was a large uproar when it was rumored that Microsoft would be abandoning LINQ to SQL, in favor of Entity Framework. This was because, at the time, many developers felt Entity Framework was an inferior technology to LINQ to SQL. To set things right, Microsoft proactively moved forward with improving Entity Framework, in time for the 4.0 release of the .NET Framework. This is good news because my initial impressions, so far, have been nothing but positive.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend