Entity Framework Code First Class Library - asp.net-mvc

Looking for an explanation and education.
I created a class library for a code first database and using the app config created a connection string.
I then added that to a MVC project.
Referencing the class library db context in the MVC project I tried to create a simple record in one of the table and it generated an error.
However, when I put the copied the connection string into the web.config of the MVC project the record was created.
My question is, why do I need a connection string in the MVC project when I am using the db context from the class library which has it's own connection string? It seemed to me that data access would pass through the class library.
I found a similar question: Entity Framework 4.2 code first in a class library ignoring my connection string which seems to imply that as long as I have it in the class library I am ok.
Any insight you can provide on this would be appreciated. Also, let me know what code you need to see and I will provide it. Since I am unsure what you would need to look at initially.
Thank you in advance.

This is by design. All the configurations are read from the config file of the application that is acting as the host. This is because you could be using the same class library in others projects and, in your case, maybe connecting to different databases.
Please, look at this documentation Application Configuration Files :
The name and location of the application configuration file depend on
the application's host
Nowadays, a web project with all the nuget packages and class libraries has a lot of dlls. It would be impossible to maintain if each of one has its own configuration file. I think it's better to be that way.

Related

Core Data Xcode 8

I started new project without core data checked and then I tried to put it in manually. So everything is fine but I have a question concerning Codegen in Data Model Inspector.
When I put class definition in Codegen field my class was redefined in appropriate to core data way so I deleted my old one. And after I saw extension of this new class where I could find all the properties.
So after I closed I couldn't find it in my project but I want to see it again.
How can I make it appear again?
When an NSManagedObjectModel is configured to generate code, it doesn't add that code to your project. Rather, it generates that code into your Derived Data, in the DerivedSources directory for the target the model is a part of.
In Objective-C, you can just use #import "ModelName+ManagedObjectModel.h" in your other code to gain access any of the entities for which code has been generated. In Swift, you don't even need to do that, you can just use the classes that were generated.
If you want to see the code for those classes, you can use Open Quickly (command-shift-O) and type in one of the class names. Xcode should take you right to the generated source code for it.

Adding Realm objc files inside own static framework

I am creating framework in ObjC first time.
I want to store data inside realm dynamically. i.e. I have JSON for schema and data, and want to create classes, it's properties, objects, etc dynamically.
I have gone through their example code, they have provided DynamicTests.m where they have created data dynamically but I don't get it correctly.
Now I have few concerns and doubts.
What files/Folders should I include to create realm database at runtime? (ie. script folder, configuration Folder, swift folder, core folder?).
How to create dynamic schema and classes with their properties?
Is there any limitation or precaution that I should keep in my mind?
Good questions!
What files/Folders should I include to create realm database at runtime? (ie. script folder, configuration Folder, swift folder, core folder?).
Realm is no different than any other framework in this regard. When building a static framework that depends on another static framework, statically link the dependent framework all you'll be all set. No additional files are required.
How to create dynamic schema and classes with their properties?
By importing the Realm.Dynamic module, you can construct RLMProperty , RLMObjectSchema and finally RLMSchema instances which you can then pass in to RLMRealmConfiguration.customSchema. Also make sure to set the RLMRealmConfiguration.dynamic property to YES.
Is there any limitation or precaution that I should keep in my mind?
The dynamic APIs are a bit verbose and not included in the HTML API documentation, so you're using Realm in "expert" mode ;). That being said, the Realm team is happy to help with any issues you might encounter (I work at Realm).

Create Framework / Library / Module of Swift Objects in Xcode

I am a (very) novice iOS/Swift programmer with a basic question about moving reusable software objects to their own ... something.
I am developing three iPhone apps that present information from three distinct data sets. Those data sets contain unique information but are structurally similar. As such, the apps share some Swift classes that are identical, specifically the classes that model the data. As I continually refactor the code, I find that when I tweak a class in one app's project, I have to remember to go to the other two projects and make the same tweaks to the same classes for those apps. It's getting to be a big headache.
What I would like to do is have one class definition in its own ... something that I can share, link, import, or attach to/from each app's project. From my online research, I suspect that the ... something is a library? or maybe it's a framework? or a module? I have found all three terms are used, but I am not sure how they relate to each other.
Given that all of the software I am writing is in Swift, does Xcode support what I am trying to do? Thank you!
It seems you have the issue of needing the same Swift class in multiple projects. You could build a Framework (aka Module) for this class then copy it in to each project. This is probably the formally correct approach but it is a bit of overkill for just a single class.
Instead, you could just make the file in the Navigator panel a reference in each project to the one actual file.
You could also make a Workspace and then put each project into the workspace and just have the file at the top level (but this may introduce some build complexity).

Zend Framwork 2 - Common class

I would like to use a common class file for all the modules. I like to keep all the common variables and arrays in that file.
I had created a folder 'Common' as like as 'Zend' library folder.
And created a class Common.php in that folder.
Afterwards, I initialized use Common/Common in controller;
Created an Object
$common = new Common();
It shown an error.
'Class not found Common\Common'.
How can I do this in ZF2?
It is really suggested you step out of monolithic thoughts with Zend Framework 2. Make modules independent and self-contained. This also means you shouldn't let big all-of-a-kind classes floating around in your application.
If you want to have for example a shared logger instance, make a log module your other modules depend on. Same holds for caching, database connections etc. With me will several others really trying to convince people not to use these kind of strategies.
When you give more insights in why you need a "common" class, perhaps more detailed answers can help you with the architectural decision. Personally I would suggest you to look first at your modular architecture instead of trying to solve this specific problem.
PS. Real answer: probably you have an autoloading issue...

How to add SOAP headers in Silverlight?

I'm trying to secure a data service used by my Silverlight, and am looking at using a custom SOAP header obfuscated into the SL and HTTPSed.
I've found any number of examples showing how to do this using IClientMessageInspector, IEndpointBehavior, and a few other things. Okay... it all looks straightforward enough.
My problem is though when i try to write my class, and inherit from IClientMessageInspector, it keeps telling me that the interface is not defined. I looked it up in Object Explorer, and it says it's in the System.ServiceModel.Dispatcher namespace. Okay.
I cannot for the life of me get this interface to be "referenced" though. I've added a project reference to System.ServiceModel, and i have the following imports in my code file (all of which are indicated to be okay):
Imports System.ServiceModel
Imports System.ServiceModel.Description
Imports System.ServiceModel.Channels
Imports System.ServiceModel.Dispatcher
Yet when i try to Implement IClientMessageInspector, it still tells me it's undefined, and offers to replace it with IClientMessageFormatter or IClientOperationSelector.
What references/imports do i need to add to get IClientMessageInspector???
Found the problem. The System.ServiceModel.dll referenced in the project is against the runtime v2.0.50727, which does not include the newer interfaces and such, instead of the framework v.3.x version of the dll.
But... now this presents a new problem, which will become it's own question.

Resources