Reputation: 2510
Im new to Entity Framework and This is my code i have written for one entity to join.
BioStarEntities BS = new BioStarEntities();
TB_USER tuser = BS.TB_USER.SingleOrDefault(p => p.sUserID=="11");
foreach (var tTemplates in tuser.TB_USER_TEMPLATE)
{
byte[] tempp2 = tTemplates.bTemplate;
}
Here instead of UserId == 11 i want to get all user entities, so what do i have to use instead of keyword SingleOrDefualt?
Thanks in advance
Upvotes: 1
Views: 892
Reputation: 3511
BioStarEntities BS = new BioStarEntities();
var tuserS = BS.TB_USERS.ToList();
This will work if you've checked Pluralization while generating entities from database. If you have not you can update model from database and mark those Pluralize and Singularize check boxes I advice.
Upvotes: 1
Reputation: 223187
If you have defined relationship in database as well as in EDMX
and if its a one to many relationship between TB_USER
and TB_USER_TEMPLATE
then you will have a property in the TB_USER
type object which will contain the related TB_USER_TEMPLATES
(probably, you may have to check the name in intellisence).
TB_USER tuser = BS.TB_USER.SingleOrDefault(p => p.sUserID=="11");
var TemplatesForUsers = tuser.TB_USER_TEMPLATES;
the above will give you all the template for a particular user.
Upvotes: 1
Reputation: 1504
BS.TB_USER.FindAll(r => r.userID = "11")
will retrieve all values. However i want to know the type of TB_User so that I can help you where you stuck.
Upvotes: 1