-
Nov 7th, 2018, 03:23 PM
#1
Thread Starter
Member
[RESOLVED] Error on Class Entity Reference in LINQ
Hi everyone,
I'm getting the following error '*****' is a type, which in not valid in the given context
for each of my table references except one.
Here is the code for the query. I also attached two pictures, 1 showing the error and another showing the EF Model.Context.cs
Code:
private void ProjectsQry()
{
var context = new ProductivityEntities();
var q = (from s in pt_Site
join t in pt_ProjectsSites on s.IDSite equals t.Site_id
join r in pt_Projects on t.Project_id equals r.IDProjects
join a in pt_ProjectSavings on r.IDProjects equals a.Projects_id
join l in pt_Personnel on a.Personnel_id equals l.IDPersonnel
where s.IDSite == 1
select new { l.FirstName, l.LastName, s.SiteName, r.ProjectName, r.StartName, r.EndDate, a.PlannedSavings, a.ActualSavings });
-
Nov 7th, 2018, 05:50 PM
#2
Re: Error on Class Entity Reference in LINQ
Shouldn't this:
be this:
vb.net Code:
from s in context.pt_Site
The same goes for the other errors. You're accessing the entity collections on the context, not the entity type.
By the way, it is convention to use singular names for entity types and plural names for entity collection classes, e.g. pt_Project and pt_Site for the types and pt_Projects and pt_Sites for the collection properties. Also, I doubt that there's justification for all those "pt_" prefixes.
Last edited by jmcilhinney; Nov 7th, 2018 at 05:58 PM.
-
Nov 8th, 2018, 03:23 AM
#3
Thread Starter
Member
Re: Error on Class Entity Reference in LINQ
I'm actually using C# not VB but either way you were correct. That removed the errors. Thank you.
By the way, it is convention to use singular names for entity types and plural names for entity collection classes, e.g. pt_Project and pt_Site for the types and pt_Projects and pt_Sites for the collection properties.
I certainty want to follow proper convention. Thank you, when I move the db to production I will make the changes.
Also, I doubt that there's justification for all those "pt_" prefixes.
Sadly my justification is that our server admin appears to have a horrible habit of putting a lot of different projects on one SQL db. Then tells the developers to prefix there tables with their project name. I wasn't going to agrue with him since it took enough just to get access to the server.
Anyways, I did some more research last night and was convinced that calling a stored procedure in SQL from the application has some advantages. I don't want to overstep and say it's better but I read a lot of good things, this read in-particular: https://stackoverflow.com/questions/...red-procedures
Do you have an opinion on the matter?
-
Nov 8th, 2018, 03:39 AM
#4
Re: Error on Class Entity Reference in LINQ
Originally Posted by justair07
Sadly my justification is that our server admin appears to have a horrible habit of putting a lot of different projects on one SQL db. Then tells the developers to prefix there tables with their project name.
That doesn't necessarily require you to use them in your C# code. If you use database-first then you can edit the type and member names in the model after you create the model and, if you use code-first, I believe that you can use attributes to specify the names to use in the database if they're different to those in the model.
Originally Posted by justair07
Anyways, I did some more research last night and was convinced that calling a stored procedure in SQL from the application has some advantages. I don't want to overstep and say it's better but I read a lot of good things, this read in-particular: https://stackoverflow.com/questions/...red-procedures
Do you have an opinion on the matter?
As an application developer, I would generally recommend that stored procedures not be your first option. If the project is driven by a DBA or someone else database -focused then you might have to use them but, in general, I'd suggest that they only be used where doing so provides a tangible advantage, e.g. a SQL query performs significantly better than the equivalent LINQ to Entities query.
-
Nov 8th, 2018, 03:51 AM
#5
Thread Starter
Member
Re: Error on Class Entity Reference in LINQ
That doesn't necessarily require you to use them in your C# code. If you use database-first then you can edit the type and member names in the model after you create the model
Did not know that, thank you!
As an application developer, I would generally recommend that stored procedures not be your first option. If the project is driven by a DBA or someone else database -focused then you might have to use them but, in general, I'd suggest that they only be used where doing so provides a tangible advantage, e.g. a SQL query performs significantly better than the equivalent LINQ to Entities query.
Thank you again, you're input is always appreciated!
-
Nov 8th, 2018, 06:21 AM
#6
Thread Starter
Member
Re: [RESOLVED] Error on Class Entity Reference in LINQ
hi jmc,
So after MORE research I'm afraid that I will run into complications if I'm trying to return multiple resultsets. Looking at my query above, does that count as "returning multiple resultsets"? If so, I think I might want to stick to LINQ to Entities Query...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|