virtual

EF的延迟加载LazyLoad

早过忘川 提交于 2019-12-14 03:28:42
延迟加载只对关联属性(Navigation Property)有用,普通属性没有这个东西。 延迟加载是一条一条的读取属性,调用一次,读取一次。 条件: context.Configuration.ProxyCreationEnabled = true;(默认为true) context.Configuration.LazyLoadingEnabled = true;(默认为true) POCO类为public,导航属性要加virtual修饰符。 注:POCO---Plain Old CLR Object,指那些不包括INSERT、DEL等数据持久化操作及任何业务逻辑的原始类。 原理分析: EF动态的生成了实体类的子类,然后override了virtual属性(所以不加virtual的话就得不到属性值) 优点:避免一次性加载所有数据,提高了加载的速度。 缺点:用一次加载一次,提高了数据库服务器的压力。 所以,当数据库的数据越多,我们用到的数据越少时,推荐使用延迟加载,反之使用预先加载。 来源: https://www.cnblogs.com/1016391912pm/p/12037869.html

Why a rule to explicitly call a virtual base class constructor in initializer list of a most derived class, when an older ancestor already has it? [duplicate]

烂漫一生 提交于 2019-12-14 01:30:00
问题 This question already has answers here : Why must virtual base classes be constructed by the most derived class? (3 answers) Closed 2 years ago . The following code: #include<iostream> using namespace std; class Man { int stories; public: Man(int stories) : stories(stories) {cout << "A man is created with " << stories << " stories." << endl;}; }; class Grandpa : public virtual Man { int pipes; public: Grandpa(int stories, int pipes) : Man(1000), pipes(pipes) { stories += stories; cout <<

When may the dynamic type of a referred to object change?

二次信任 提交于 2019-12-13 17:03:53
问题 Let us begin with an example: #include <cstdio> struct Base { virtual ~Base() {} virtual void foo() = 0; }; struct P: Base { virtual void foo() override { std::printf("Hello, World!"); } }; struct N: Base { virtual void foo() override {} }; void magic(Base& b); // Example implementation that changes the dynamic type // { // void* s = dynamic_cast<void*>(&b); // b.~B(); // new (s) N(); // } int main() { std::aligned_storage<sizeof(P), alignof(P)> storage; void* s = static_cast<void*>(storage);

Vector of virtual class : are pointers the clean way to go?

╄→гoц情女王★ 提交于 2019-12-13 15:25:15
问题 Note: This is almost a duplicate of this entry: Abstract classes and Pointers I need to create a vector of virtual classes. Here the idea: #include <vector> using namespace std; class VirtualFoo { protected: VirtualFoo(); virtual ~VirtualFoo(); public: virtual void doStuff()=0; }; class ConcreteFoo: public VirtualFoo { public: ConcreteFoo(double a); virtual ~ConcreteFoo(); void doStuff(); private: double a; }; class Foo { public: Foo(std::vector<VirtualFoo> foos); virtual ~Foo(); void

virtual destructor in c++

时光怂恿深爱的人放手 提交于 2019-12-13 11:30:37
问题 In the code below, why is the ~Derived() destructor called automatically? #include<iostream> using namespace std; class Base { public: virtual ~Base() { cout << "Calling ~Base()" << endl; } }; class Derived: public Base { private: int* m_pnArray; public: Derived(int nLength) { m_pnArray = new int[nLength]; } virtual ~Derived() { cout << "Calling ~Derived()" << endl; delete[] m_pnArray; } }; int main() { Derived *pDerived = new Derived(5); Base *pBase = pDerived; delete pBase; return 0; } 回答1:

Why virtual base class constructors called first? [duplicate]

南笙酒味 提交于 2019-12-13 11:26:39
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: In C++, what is a virtual base class? virtual inheritance why is it so that the constructors of virtual base classes are called from most derived class...and in the inheritance hierarchy first the objects to virtual base classes are created...whats the logic behind this? I understand that using virtual inheritance as in diamond structure using virtual inheritance only one copy of the most base class is created

method of super-class called WHEN super has a str attr + instance of sub is created in a loop + instance is stored in a vector as a pointers of super

允我心安 提交于 2019-12-13 07:59:20
问题 I can't reach a method of a sub-class' instance when several conditions are merged : There is in the super-class an attribute of type string. The instance have been created in a loop The instance is stored in a vector that takes super-class pointers It's so look like this : class Parent { public : string name; virtual void myMethod() = 0; }; class Child : public Parent { public : void myMethod(); }; void Child::myMethod() { cout << "I'm a child"; } int main(void) { vector<Parent*> children;

Virtual include not working

为君一笑 提交于 2019-12-13 06:27:35
问题 I have recently taken over a website written in Classic ASP which i had no previous experience with. In the root of the site the default.asp has an include: #include virtual="/inc/common.asp" However when hosted on the web server or locally (IIS) it returns with an error which says the include file 'common.asp' could not be found. The inc folder exists in the same directory as the default.asp and the common.asp is in the inc folder. Any help would be appreciated! 回答1: You say that the inc

C++ lnk error 2019 unresolved external symbol virtual errors because of an interface…(?)

限于喜欢 提交于 2019-12-13 05:30:24
问题 Im having problems with making a good interface and use it... My setup overview: An "interface" GraphicsLibrary.H ... virtual void drawPoint(const Point& p, unsigned char r, unsigned char g, unsigned char b, double pointSize); with an "empty" GraphicsLibrary.ccp! because its an interface, so "OpenGL" is an graphics library... so i have an OpenGL.CPP with: void GraphicsLibrary::drawPoint(const Point& p, unsigned char r, unsigned char g, unsigned char b, double pointSize) { //some code } which

When my base class and derived have the same function, does it HAVE to be virtual?

六眼飞鱼酱① 提交于 2019-12-13 01:25:39
问题 So i have a project I'm working on with quite a hierarchy. In the base class of this there is a function reset() that gets called throughout all the derived classes. All I'm confused about is that, since this reset in the derived class basically just resets it's private variables and then calls it's preceding (higher) class' reset() function does the reset function have to be virtual? Eg. class Base { private: int some; public: void reset(); }; class Derive : public Base { private: int some1;