Avatar of akohan
akohan
 asked on

Will this C# picece of code acts same as an SQL query?

hello group,

In a code (following) it seems some data are retreived from a MS SQL 2008 database. Does this mean there no need for any query or stored procedure in the database physically?

I'm new to this type of coding...

Will this get the data?

Thanks!
var context = ObjectContextHelper.CurrentObjectContext;
            var query = from c in context.Countries
                        orderby c.DisplayOrder, c.Name
                        where (showHidden || c.Published) && c.Allowed
                        select c;
            var countryCollection = query.ToList();

Open in new window

.NET ProgrammingC#

Avatar of undefined
Last Comment
akohan

8/22/2022 - Mon
Tyler Laczko

You do not need to create a stored procedure if you are created your select statements in your code.
SOLUTION
Tyler Laczko

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
elimesika

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
akohan

ASKER

Do you mean this piece of code will do the job of retreiving data from table?
akohan

ASKER

Elimesika,

Thanks for your help. I have added a new method to an existing code  (I just followed other methods to see how they work) my method now works but doesn't return any data off the database. so do you mean I need to do something with Linq?

Thanks.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Zakabog

var query = from c in context.Countries
                        orderby c.DisplayOrder, c.Name
                        where (showHidden || c.Published) && c.Allowed
                        select c;

That looks like a query, does the code work? I'm not quite sure what you're asking.
akohan

ASKER

yes it is a query but I'm new to this kind of query since I'm not famliar with linq
now, what I'm trying to say is that there is a methodA() uses this and gets the information so I have followed its step but mine doesn't bring back any data.
what could be missed in my work?


ASKER CERTIFIED SOLUTION
Todd Gerbert

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
akohan

ASKER

Thanks for the information you shared, OK, I found out that I had forgotten to call the function in the caller !!! BUT now I'm getting an error as following:

Mapping and metadata information could not be found for EntityType 'Test-Solutions.BusinessLogic.Directory.CustomerType'

what causes this and how can I fix it?

Regards.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
akohan

ASKER


OK found the problem, there were two reasons:

1) My database model (TestModel.edmx) was not updated. However, after this step still there still was the same error message
2)The name of entity or table was not as the name in database... so I had to fix the naming but step 1 was requred anyway.

Thanks to all for your feedback.

akohan

ASKER
Sorry for the delay ... been out of town for a month with no access to internet!