EntityFramewok loading vybraných Entit   otázka

C#, Entity Framework

Ahoj, v EF Code First mám vazbu 1:N mezi User a UserDevice, kdy jeden User může mít N UserDevice.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
public class User
    {
        [Key]
        public int Usr_Id { get; set; }
        [Required]
        [MaxLength(35)]
        public string Name { get; set; }
        [Required]
        [MaxLength(35)]
        public string Surname { get; set; }
        [Required]
        [MaxLength(35)]
        public string Location { get; set; }
 
        //NAVIGATION
        public User()
        {
            UserDevices = new List<UserDevice>();
        }
 
        public virtual ICollection<UserDevice> UserDevices { get; set; }
 
    }
 
public class UserDevice
    {
        [Key]
        public int UsrDev_Id { get; set; }
        [Required]
        [MaxLength(50)]
        public string PurposeOfUse { get; set; }
 
        // NAVIGATION
        //User can have many UserDevice
        public int Usr_Id { get; set; }
        public virtual User User { get; set; }
    }

A ještě konfigurace ve FluentAPI

1
2
3
modelBuilder.Entity<UserDevice>()
               .HasRequired<User>(r => r.User)
               .WithMany(m => m.UserDevices);

Můj problém je, že když zapíšu

1
2
var select = from s in db.Users
                         select s;

tak se mi naloaduje nejen seznam User, ale i seznam UserDevice ke každému z nich. Jakým způsobem můžu udělat select, abych získal pouze seznam User bez UserDevice.

nahlásit spamnahlásit spam 0 odpovědětodpovědět

Nemáte náhodou zapnutý lazy loading?

Více viz např. zde:

https://msdn.microsoft.com/en-us/data/jj...

nahlásit spamnahlásit spam 0 odpovědětodpovědět

přihlásit pomocí externího účtu

přihlásit pomocí jména a hesla

Uživatel:
Heslo:

zapomenuté heslo

 

založit nový uživatelský účet

zaregistrujte se

 
zavřít

Nahlásit spam

Opravdu chcete tento příspěvek nahlásit pro porušování pravidel fóra?

Nahlásit Zrušit

Chyba

zavřít

feedback