Long listener, first time collar.
I'm probably taking a wrong look at this, so any help would be great.
I am using C #, MVC 4, Code First, Unit Framework 4.3, and AM; the razor.
I am trying to split EF data classes & amp; Some methods were included in a separate class project so that they could normally be in the context of many other projects. I made this simple example to highlight this issue as much as I can.
So I have a class project:
public MyGeneric (name of string) {ID = Guid.NewGuid (); Name = name; } Get Public Guide ID { Set; } Public string name {get; Set; } Public Zero AddThis (MyGeneric obj) {Use (var db = Activator.CreateInstance ()) {var myOthers = Mo. db.MyOther where mo.OtherID == obj.ID select mo; MyOthers.ForEach (MO = & gt; db.MyOther.Add (MO)); Db.SaveChanges (); }} And then I can refer to it in a main project such as:
public class sample inherits: Ignorative {public sample inheritance (string denominator) , String secName): base (new name) {SecName = secName; } Public String SecName {get; Set; } Public Zero DoSomething (SampleInherit obj) {base.AddThis (obj); // What other things}} What am I trying to do genericis (is it a word?) Some classes do it with their own methods in a different side project
Use EF DBCTNET to create / access the database, Allow adding more properties, Method / processes that affect the underlying data Supply, For Main Project and More A proper name will be given. Now if I just base class in classes in main projects, it works in addition to all the Base Works references myDbContext & amp;
Can you tie a data stretch late or do I paint myself here in a corner?
Cheers for all help you can give
I think that What you are trying to do. Basically, you want to do this, prepares a class project that includes your institutions and your archipotory. From there you create your repository class and make the concrete implementation of the IRPGetry. You use your business logic level to access the repository through an IRAP facilitator. And access your data there Public Interface IRAPSorporation & lt; T & gt; {IQueryable & lt; T & gt; Get (); Insert Boole (T organization); Bull Update (T Entity); } then create your repository
PublicRequired MyRepository & lt; TContext & gt; : IRAPSource & Lift; Entity type & gt; Where TContext: DbContext, new () {Personal TContext References; Public MyRepository (TContext Reference) {this.context = context; } Public IQueryable & lt; T & gt; Get () {reference reference.EntityTypes; } // Insert and Update Logic} Create your business logic at the end
Public class BusinessLogic {private irregularity & lt; EntityType & gt; Stores; Public BusinessLogic (IRPository & lt; EntityType & gt; repository) {this.repository = repository; } Add Public Zero (EntityType obj) {bool isNew = // if is new (isNew) {this.repository.Insert (obj)} else {this.repository.Update (obj); }}} Then call your business logic
IRAPSorporation & lt; EntityType & gt; Repository = New My Repository & lt; MyDbContext & gt; (New MyDbContext ()); Professional Public Service = New Commercial Local (repository); Service.Add (New EntityType ()); I do not think you want late binding of data references, it is better to use generic for performance considerations (with the above example). Also, with this method you can instantiate a data reference and pass it to your business services so that at the Etiquette Framework ADD, keep track of your institutions rather than urging to render a new data reference for each call . Plus with this pattern you can do all kinds of good stuff, such as using IoC containers, such as ninja to make those commercial services for you, and use socks to make unit tests for your code. Do (mocking your repository)).
Comments
Post a Comment