I have a MVC4 project which is going to be a large system, I want to split the database management into its own project so in my solution I will have MyMVC4 and MyMVC4_Data
I will add MyMVC4_Data as a reference to the main MyMVC4 project. I believe there will be multiple projects in the future so splitting the data makes sense.
My question is, what sort of project template will be sufficient for the database stuff, all it will have is Linq and manager classes for each table to insert delete etc. I don't think it would be necessary to include a new MVC4 project as the overheads will be too big for what is needed. The project must be referable by the main project
Any suggestions would be appreciated
Thanks
I'd use a Class Library project. From the docs:
You can use the Class Library template to quickly create reusable classes and components that can be shared with other projects.
Related
I'm writing a program in C# that has two classes, Foo and Bar. I have two executables that will use them, GenerateFooBar and SearchFooBar. My question is how should my solution be partitioned? From what I can gather, everything can live in one solution and each executable should have it's own project. Should Foo and Bar
share a project?
each have their own projects?
go with one of the other projects?
something else?
Thanks for the help! I'm coming from Java if that's helpful.
In your solution, create project called for example Common, and put all your classes and businbes logics there. Set project type as Class Library
Next add your other projects and in them Add Reference to Solution Common project to use it.
If multiple users are meant to work with the shared library, the best solution will be to create the local nugget
Create a shared project and put Foo and Bar into it. Reference that project from both executable projects.
If you later have many developers depending on the shared library you might make it into a Nuget package that you publish and have them depend on that.
From what I can gather, everything can live in one solution and each
executable should have it's own project.
Yes, you are right.
how should my solution be partitioned?
Totally depends on you and how you would like to manage it.
You could create one project, multiple projects, each separated projects, etc.
But, to reuse code as much as we can and to give a more structured way. Here is what you can do.
Make one Project which will hold the ApplicationServices, Helpers, etc eg: Foo and Bar.
Make Another Project which will hold the application itself (Could be two projects one for search and one for generate). You can add reference of service project to your foo and bar projects and to any other project you create in future.
So in the end you will have 2 or 3 projects (depending on you)
1- ApplicationServices
2- Generators/GeneratorServices/GenerateApplications/anyname
3- Search/SearchServices/SearchApplications/anyname
this might be a bit dummy question but I'm confused...
I have a simple C# solution in VS with 3 projects
UI
CORE
DAL
Now, I've added 'DAL' as a reference inside 'CORE' so now I can see and use my DB methods.
However, since I want to send one of the 'CORE' classes to my INSERT method which is inside 'DAL' (to insert the full object) I cannot see or access it, and I also can't add a circular reference and add 'CORE' to 'DAL'.
public void InsertOrUpdateResultData(MyObject _obj)
MyObject is from 'CORE' project.
Any help is appreciated.
Thanks
You can extract the common classes inside a separate project and reference it from the CORE and DAL. Eventually you can create DTOs.
If you encounter such situation you are probably doing something wrong. I would suggest to rethink structure of your solution. Maybe it would be worth to create another library that can be included in both CORE and DAL projects.
If you're using the same class across multiple projects, as is your case here.. have you thought about using a shared project? You can add the shared project to all other projects you need. Based on what you've stated, it would probably be a better solution.
http://dailydotnettips.com/2015/07/28/using-shared-project-across-multiple-applications-in-visual-studio-2015/
I have three parts of a project, one is Core(bussiness) project, one is webproject and the last is the test project.
I want to call some classes that I saved in one folder from core project to webproject without calling the dll of the core project. Since core project is already refereed into the webproject. So it will call the cycling if the references and not allow me to do that.
How I can use classes from core project to web project without call the DLL?
I Have already tried 'using', The code is following. It's not working for me.
using BlogEngine.Core.API.PageML; // I need to call all classes from this folder
using BlogPage = BlogEngine.Core.API.PageML;
namespace admin.Settings
{
public partial class DownloadInsertPage : System.Web.UI.Page{
protected void BtnPageMLInsertClick(object sender, EventArgs e)
{
var reader = new PageReaders(); // the class, I want to call from the core project
}
}
Thanks
Your question is unclear ("since web project is already refereed into the webproject" for example) but you should really make the web project have a reference to the core project, but not the other way round. The core business logic shouldn't know about your web "view" onto it, but the web project should absolutely know about the core business classes.
If you have classes in the web project which you're currently referring to from the core project, you should probably move them to the core project - or to a third project which both of the other projects refer to, if they don't logically belong in the core project itself.
Your model may benefit from contract interfaces - that would help you redesign your current model in order to avoid circular references. Here's some posts about this:
a design to avoid circular reference in this scenario
Resolving Circular References (C#)
Now, I may have misunderstood your question, and you'd rather benefit more from learning about add-on models. In that case, this post may be of some help:
C# Plugin Architecture with interfaces share between plugins
You cannot.
If you need these classes to be accessible in both assembly, you should create a third one that would be referenced by both of them although this should be reserved to cross-cutting concerns only (e.g. logging logic).
Thank you guys for your valuable comments..
I want to share, what was the problem and how I resolved it.
I build the core project after created some classes into the PageML folder and build it without calling this folder into the web project. and update the reference(dll) of core project in the webproject. and it's working for me.
Thank you All
Keep clam and do coding.
:) have a nice time
As a C# developer, I'm familiar with adding assembly references in a Visual Studio project. It looks like you can also add a database reference to a project.
My question is: Why would you want to add a database reference to a project?
Does this let you do something special like track dependencies on database tables or columns?
For SSDT projects such as you mentioned, there are two main use cases for database references:
Composite projects are a great way to handle cases where you have common schema elements such as tables that are shared by a number of databases. This maps to the concept of inheritance and object reuse in C#, and helps you avoid duplicate code and improve your design.
External database references are used when your code such as sprocs and views needs to reference elements from other databases. It is useful in resolving references and ensuring the project can build successfully. In this case it maps pretty directly to the concept of referencing Apis in C#.
Note that the help you linked to is the old help for VS2010 projects, more accurate help for SSDT is here.
Also you might notice that you can also add references to .Net assemblies, that may be necessary if you are writing SQL CLR code in your project and need to reference external code.
You cannot add a reference to a database project. The page you linked describes adding a reference to a database in a database project. The reference allows you to run scripts against the database within the project.
I'm using EntityFramework 4 in my WPF desktop-application (NS: MyCompany.MyProduct).
Now I want to create the same application in ASP.NET (NS: MyCompany.MyProduct2), with the exact same functionality... Hence I need to use the exact same database as the WPF application already does.
Additionally, I want to create a new executable (hence a new wpf project) on top of my primary WPF project, that also uses the same ConnectionString like the WPF / ASP.NET-Application, to display some reports.
So I figured out I'd need to share the .edmx-Model (NS: MyCompany.MyProduct.Models.DBModel.edmx) and the ConnectionString that is already persistent in the app.config of the WPF app or the web.config of the ASP.NET-App.
What is the best or recommended way to do this?
What is the best or recommended way to do this?
Create a class library project and put EF model in there and share it between your WPF/Web projects. The app.config file of a library project isn't picked up by the parent project therefore you will have to manually update your web.config file to add the ConnectionString section.
This approach allows you to share business logic between your WPF app & your web app. If they are essentially the same app but on different platforms, then you should only be re-implementing the UI - this is one of the major advantages of the MVC pattern.
Agree with #James here. Don't be afraid of adding library projects to your solution. So you would have a project called MyCompany.Model that contains your EDMX. (Actually, you might find later that you want to use the T4 generation to split your model off from your DbContext or ObjectContext, but that's another discussion.)
With Visual Studio you can actually add a project--your EDMX project--to more than one solution. Be careful not to make changes to the EDMX project when editing one solution that break the other, though.
Respectfully, you may find that it's not ideal to use the GAC here, especially if your EDMX is still evolving.
As for connection strings, these are one thing that you tend not to share between projects. Typically they are in the app.config (or web.config) for your executable project. This can be a gotcha, because if you use a library project to hold your EDMX, EF will automatically create an app.config in the library project, with the connection string in it. But .NET never uses an app.config for a DLL. The only reason it's there is to give you something you can copy/paste into the real app.config for your executable (WPF) app.config or the web.config.
If your goal is to share the single .edmx dll between all three applications on one machine, the best way to accomplish this is to sign the dll, then add it to the GAC. If the dll will remain on different servers, there is no need to GAC the dll, you can just reference it in your projects, and add the connectionstring entry in the respective .configs.
GAC: http://msdn.microsoft.com/en-us/library/yf1d93sz(v=vs.100).aspx
Install a DLL to the GAC: http://msdn.microsoft.com/en-us/library/dkkx7f79.aspx