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

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

Simple LINQ to SQL question

Posted By:      Posted Date: October 13, 2010    Points: 0   Category :ASP.Net

Someone help me with what I'm missing here...

I have a VERY simple file as you can see... just three tables.


The Problem is that if I do this somethign like this....

var patients = from x in db.CT_Patients
                     where x.CT_Visits...... (error here)


It doesn't display child properties for CT_Visits from CT_Patient like it should. I only get the standard LINQ queries like Select, Where, Orderby etc... What am I missing???


View Complete Post

More Related Resource Links

Simple question.... LINQ on Datatable

Hi all,Simple one this I am sure for those who use LINQ! :)I basically have two tables that will be stored in viewstate until I save the data to the database.  I need a way to query the datatables, delete remove etc.  Is this possible in LINQ?So for example, delete/select rows from the DataTable that have a particular ID etc...Thanks,Mark

A very simple question on the LINQ Count function, but I can't figure it out....


Hi guys, I think this must be really simple but for some reason I can't get this to work.  I have an arraylist of stock ticker names and the same names can appear multiple times in the list.  I am trying to create a LINQ query to find which ticker names appear a certain number of times in the list. 

The arraylist is like: {Dell, Citi, Appl, Appl, Citi, Msft, Dell, Appl, Dell}

If I want to find which tickers appear 3 times in the list, which is named "stocklist", my current query is:


Dim newquery = From ticker In stocklist _

Where ticker.count = 3 _

Select ticker


But the query keeps giving me an error when I try to run it.  I'd greatly appreciate if someone could please let me know how to correct this problem.  Thanks in advance!

C#, LINQ: (List<>) Question???


Hi Everyone,

I have a strange problem:


There is an entity (Table) called "Filters" in my .edmx which has all my tables and stuff in it (to use it for LINQ queries)

I have created a class called "CustomFilters" which inherits "Filters". So now my cutom class has all the properties of the original "Filters" class (table) and 1 more additional property that i wanted which is a List of "CustomFilters":

List<CustomFilters> children = new List<CustomFilters>();

Now i get all my records into:

List<CustomFilters> theOriginalList = new List<CustomFilters>();

NOTE: first all records are tken into a List<Filters> and then these are added into List<CustomFilters> where List<CustomFilters> for children of that record is added, and then children of the child records, and so on......

so now, every record is an instance of CustomFilters which has a property named "children" which is a list again; and each child again has instanaces of "CustomFilters", and each instance again has children...and on and on and on.....

(basiacally its a data source for a treeview in my silverlight control)

every thing is good and working as expected.


Entity framework simple question




First I am newbie using EF - so sorry on this basic question


I have a Project Table that relate to Company Table


When I Map with EF I Do not have property of CompanyId in the Project Object

But I have related Company Object


For example

Project p = new Project();

p.CompanyId è does not exist!

When I try addingit myself I get this error:

If I need just the Company id, and I don't want get it like

p.Company.CompanyId - because than the application try connect again to the DB and I don't want this, because I need just the CompanyId.

What the best regular way to get it?


A simple Data Modeling Question


I have a data modeling question that hopefully this fictious example will help explain.  My application is data driven and the classes reflect the tables to a large degree.   In this example my database has two tables:

  • VendorMaster with an int Primary Key of VendorID
  • VendorContact with an int Primary Key of ContactID

The VendorContact table also has a Foreign Key of VendorID in order to associate the contact with a specific Vendor.  In this example a Vendor can only have one contact.

My question is how to represent these two tables in terms of classes.  In my current design I have two classes:

  • VendorMaster
  • VendorContact

In order to represent the relationship between a VendorMaster and VendorContact, my VendorMaster class contains a property called VendorContact.

My questions are about the VendorContact class and how it represents the relationship between a VendorMaster and itself.

Option #1

The VendorContact class should contain an int property of VendorID

Option #2

The VendorContact class should contain a VendorMaster Property

I am not sure which option is the 'best' option to take. My concern is that if I go with option #2 that I would create a cyclical relationship between the VendorMaster and Vendo

GridView Question - Please Help Me...Should Be Simple...

Hello,I have what I think should be a simple GridView question but I can't find the answer.When I want to update a row in Gridview I click on the "Edit" link.  It takes me into the row of the GridView where I can edit the values.Here's how it looks:   CustomerID CompanyName Edit 001 IBM Microsoft Apple Google Edit 002 IBM Microsoft Apple Google Edit 003 IBM Microsoft Apple Google Edit 004 IBM Microsoft Apple Google When I click on "Edit" it looks like:   CustomerID CompanyName Edit 001 IBM Microsoft Apple Google Update Cancel IBM Microsoft Apple Google Edit 003 IBM Microsoft Apple Google Edit 004 IBM Microsoft Apple Google As you can see, I now have the ability to update the CustomerID.  I don't the user to be able to update the CustomerID, only the CompanyName via the DropDown.How can I change the GridView to ONLY allow me to update the CompanyName?ThanksJason   CustomerID CompanyName Edit 001 IBM Microsoft Apple Google Edit 002 IBM Microsoft Apple Google Edit 003 IBM Microsoft Apple Google Edit 004 IBM Microsoft Apple Google

Simple data binding question

Newbie binding question here: is it possible to bind a control in XAML to a StaticResource by passing in the key via a data structure? Basically something like this: <TextBlock Text="{Binding ImageKey}" /> <Image Source="{StaticResource ResourceKey={Binding ImageKey}}" /> <-- doesn't work   The TextBlock binding on the first line works correctly, it extracts the key of the StaticResource from my data structure and displays it correctly. What I'm trying to do is get the Image control to bind to the StaticResource with that name (which happens to be a BitmapImage).      

Noob Question - Using Linq in View

I just inherited an MVC2 application. So far my only experience with MVC is reading the Nerd Dinner sample chapter and downloading the nerd dinner app. I do plan to dive much deeper but i need a quick answer because i have to hit the ground running. So basically in the main Index view the view model is being passed as an IQueryable. Then he is doing some queries on the view model to loop through the data. See example below:<% if (Model.Where(w => w.State == workflowStep.Key).Count() > 0) { %>To me, even though minor, this is business logic and shouldn't be in the view. Shouldn't any type of logic like this be sorted out before you get to the view? Or is this common practice in MVC?Basically i want to know if I should spend time refactoring this thing or just go with the flow.  Thanks.

Simple Question

hi i m using Resource file for localization everything cool I pick the date value and i format it then i set the HtmlTableCell InnerText value the date value shows in Thai format i don't want to show the date in thai language format how can i prevent this 

Simple Viewstate question

Consider a page with asp textbox and a button. textbox's "EnableViewstate" property is set as "False". In page directive also i set the Page's "EnableViewstate" property as "False". If i type some text (i.e., like "This is sample text") on the text box and click the command button. After the postback also that text box contains the same text ("This is sample text") which i have typed. I have set the view state in page for false. Then how the state is maintained?  whats the reason behind that? Thank you.

Simple Question

 Hi Guys,    I had a webservice method, Whenever it throws an Exception Object, I justwant to catch that Exception Object from the AJAX function. Is it possible? If so, please give sample code snippet ASAP.  Thanks in advance.

Linq to SQL - DeferredLoadingEnabled/DataLoadOptions Question

I am reading a book that suggests that when you need data from a child table that you should both: Set DeferredLoadingEnabled to false and Set the DataLoadOptions This seems a bit redundant to me.  If DeferredLoadingEnabled is false, why would you need to set the DataLoadOptions?  Doesn't turning off deferred loading mean that the child tables will automatically get loaded when the query is executed? Thanks

LINQ left outer join question

I can do this in other ways, but am looking for the "LINQ" way of doing this: Table1: People (PersonId,SchoolId)Table2: AssignedPeople (PersonId,SchoolId,RoomId) I want to select the people in Table1 within a particular SchoolId that are not in the assignedPeople table (in a particular Room).  The SQL is: select p.* from people p left outer join assignedpeople ap on p.PersonId=ap.Person and p.SchoolId=ap.SchoolIdand ap.RoomId=@roomId where p.SchoolId=@SchoolId and ap.PersonId is null I tried this LINQ (VB,NET):dim SchoolID as guid=...dim RoomID as guid=... (from p in dc.people where p.SchoolId=SchoolIdgroup join ap in dc.AssignedPeopleon p.PersonId equals ap.PersonId and p.SchoolId equals ap.SchoolId into groupfrom g in group.DefaultIfEmptywhere g.RoomID = nothing) but I can't get the ap.RoomId=@roomId part into the right place, should be something like:group join (from ap in dc.AssignedPeople where ap.RoomId=RoomId) Any help would be appreciated,Reuven

Another Simple Question - Adding a Picture to My Site

Hi, I'm trying to add a profile picture to my profile on SharePoint 2010 but under Edit my profile there isn't a option. I believe it should normally be under Basic Information. Is there a way to add this option?

Question on WCF service with Linq to SQL on 64-bit system

I'm trying this question one more time since I realized the work in in a 64-bit environment. I have a WCF service which runs in production in a 32-bit environment using VS2008 and .NET 2.0. We made a big change to our environment (lots at the same time) and I moved the services to VS2010, .NET 4.0, and 64-bit processes.  I wrote a new service and deployed it under IIS.  If I browse to the service I get the example screen and clicking on the link gives me the metadata.  So all of that is working. In my services I create a Linq to SQL context, perform a query, then return the result set as an Array.  I wrapped the context creation with a using.  My tests returned an exception "Attempt to access an object that has already been disposed".  I traced it down and found that the code executes, forces the query, returns the results, exits the using statement (disposing the context properly) then exits the method.  The next thing I get is the exception, inside framework code, and it is linq code attempting to fulfill the query once again. I have searched until I'm blue in the face trying to find prior incidents and fixes but all I found was one post, two years ago, same problem with less debugging, and no answer to the problem other than 'don't use the using statement' which is a bad suggestion.  So for a work around I wrote a Co

Simple Excel Import Question

I have an excel file I am importing into a table. The excel file is named with a date (02102010_Excel_file.xls). I created a very simple import package. This simple two object package - Excel Source to OLE DB destination works just fine. But..   My problem is that the Excel file name will change every day to todays date (09162010_ExcelFile.xls) So,  I need to change my Excel Import  to something like *.xls but that doesn't work. How can I Import a *.xls file? qeqw

Simple but unusual SQL 2008 peer2peer replication concept and question

Hi, I am not an SQL expert, but have to set up 3 remote SQL databases that need to be synchronised with each other. This is unusual because the locations are tiny atolls in the middle of the Pacific.  Communication between them is by satellite only which has limited bandwidth and is expensive.  The total population (thats all the people) on each atoll is only 500.  There is likely to be a maximum of 40 potential users per atoll and each SQL database is for internet login authentication only (Radius).  So the databases are tiny and have a very low update rate. What is the simplest way to synchronise the databases?  Doing this just once each night at around 4:00am would be best.  Peer to peer replication sounded right, but I do not want our extremely limited bandwidth taken up by this traffic when all we need is for the databases to be synchronised by the next day.  Also we are running MS SQL 2008 R2 Workshop edition and I am reading that this does not support peer2peer replication. The hardware is a laptop - since hot moisture laden salty air is very corrosive for traditional servers and power is intermittant at best.  Each atoll gets an identical system. Can anyone suggest a solution or ideas?  I am happy yo answer questions.  Thank you.
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