Total Microtheories:7441 TotalHits: 244823 Email Us | Add MT | Help Using the Site


[Valid RSS] | RSS Feed

Most Recent Microtheory

(hits=6) This code snippet demonstrates how to use IQueryable to dynamically expand the linq expression tree. The where clause appends to the expression tree. The IQueryable is not evaluated and executed until the foreach. The MapChartOfAccountView flattens the data into a business view.[Learn More...]
(hits=6) Overview: In this code snippet, I demonstrate how to override an api route. It can be confusing, how to override the route. At the controller level the route is defined as api/[controller] and by convention the controller is the name of the class, in this case, "GeneralLedger". In my angular component, I make a get call using the path api/GeneralLedger(the controller)/BySummary/2018 and await results. The Web api maps to the controller and the uri routing BySummary with the parameter fiscal year, [Route("BySummary/{fiscalYear}")]. The parameter is received an the dataservice calls the fluent module with its unit of work domains to extract the data from the sql server database.[Learn More...]
(hits=5) The web api controller is a file named "TimeAndAttendanceController" and by convention the path is api/TimeAndAttendance with a route defined as "TAViews". I pass the field names of the filterTimeAndAttendance class as a query string parameters. I like classes as parameters because the parameter list can become large.[Learn More...]
(hits=7) This code snippet demonstrates how to call a web api get using Postman and bind the parameters into a parameter class filter. The webapi receives the query string parameters and parameterizes them into property fields using the class setters. This is an amazing feature of C# suggesting that by inference the properties can be discovered and the properties bound. In a previous article, I demonstrated how to use reflections to expose the class and a custom Mapper class to assign the properties values.[Learn More...]
(hits=6) The mapper class a generic type T defined as TimeAttendanceView which is instantiated The properties of TimeAttendanceView are stored in a variable call propts. The linq IQueryable object uses the TimeAndAttendanceView class property name to retrieve a value and type. The value then is assigned to the new TimeAttendanceView object.[Learn More...]
(hits=6) Linq is very comparable to sql. You can perform joins, left joins, group bys, and aggregations. Subquerying in linq is done in the select section using the any method and a lambda expression. I check the TimeAndAttendanceScheduledToWork table to see if an employeeId and scheduleId, exists, indicating the employee was scheduled to work. My linq select statement matches to the name and type of my business class by design.[Learn More...]
(hits=8) In the code, sample I have demonstrated, the linq to class direct mappings and the linq to class using reflections.[Learn More...]
(hits=7) This code snippet demonstrates, how to transform a TSQL query into a linq query and then transform the linq select dataresult into a business view class using reflection. The Mapper class requires and exact name match and type returned by the linq query. There are reasons not to automate the transformation between the linq query select and the business view class. Reason one, the compiler detects type mismatch; the mapper resolves name and type of the object properties at runtime and errors in type and name can occur; and last, reflections runs slower than direct mapping.[Learn More...]
(hits=6) The lazyloading allows access to the foreign key data. for example, budget.Account.Description is references the foreign key table Chart Of Accounts. Using the accountid a relationship is established between the budget table and the chartofAcct table.[Learn More...]
(hits=6) The lssWebApi Budget Controller route is discovered and the httpGet Get is execute. Within the Get method a fluent class called BudgetModule is instantiated and the its classed called FluentBudgetQuery interface method Query() is invoked. The Query method calls its unit of Work class which calls its budgetRepository method GetBudgetViews. The repository method GetBudgetViews uses the datacontext to access the budgets dbset and returns a IEnumerable list of BudgetViews using a linq statement. The lazy loading allows access to the parent data of the entity frame work class budget.[Learn More...]
(hits=9) The Datacontext is initialized as lazying loading for the class mappings to retrieve data from entity framework code first classes. Authentication credentials are stored in the appsetting.json.[Learn More...]
(hits=10) The lssWebApi baseurl is stored in the dataservice class. The WebApi on the lssWebApi assembly is called using the httpClient in the dataservice class. The api path on the lssWebapi assembly is invoking using the httpClient.GetAsync method and it awaits the results from the assembly.[Learn More...]
(hits=13) The @Inject('BASE_URL') dependency injects the base url of the angular program. In my solution, I multi start the lssAngular and lssWebApi projects with the lssWebApi starting first. The BudgetController by convention is Budget and restful rules apply. So a get without an parameter will return a collection of List of BudgetViews. The javascript method .subscribe works like an promise returning data results once the lssWebapi completes its task. The angular IBudgetView should match the field names and types of the C# BudgetViewClass. The typescript interface is used to define the data shape of the result.[Learn More...]
(hits=12) Overview of the process flow begins with angular component making a get request to an local web api controller called budgetController this mvc webapi controller then calls the lssWebApiController using a dataservice class that I created and invokes the budget module query to return a list of budgets. The returning dataset is returned as a json string and assigned to an typescript interface and consumed in the angular report.[Learn More...]
(hits=14) In this code sample, I have two projects, one is an Angular 2 component project for the web interface and the other is the web api project with the entity framework code first classes, unit of work, and fluent code modules. I will demonstrate how create a connection between the angular project and the web api project. When testing or debugging webapi using xunit, make sure to change the appsettings.json property "Copy to output directory" to "always" because by default it is never. Otherwise you get the missing appsetting.json generates an error while referencing class methods in your web api.[Learn More...]
(hits=12) In core the database.sqlquery command was not added. I found a work around on github that involved an static extension methods which I am grateful to have found. In the code snippet I demonstrate the long method for interacting with stored procedures and the short method. In the long method, I create an ado command object from the datacontext with the createCommand method. The command object is initialized as a storedprocedure commandtype with the name of the stored procedure and the parameter forwhich I pass called "NextNumberName". The NextNumberName is the entity identifier in the NextNumber table. The ado database connection is opened and a ado reader created using the executereader. The returning dataset can be accessed by name or ordinal position in the recordset. You are required to type cast the returning data. In the short method, an extension class method is created called sqlquery. The database context is passed along with the name of the stored procedure and a list of sqlparameters. The method is typed as T an generic type that you provide. Using reflection, var propts = typeof(T).GetProperties(); returns the class properties of the generic class that is passed. I pass the type T of NextNumber. A model of type T is new up and the data of the returning dataset is setvalue to properties in the NextNumber class of generic T. A Ilist of type T is returned from the extension method.[Learn More...]
(hits=9) The fluentAddressBookQuery has an method called GetAddressBooksByExpression which accepts an delegate function of type AddressBook. Linq expressions can be passed as a delegate function to the repository dataset through unit of work. AddressBookRepository inherits from the generic parent class repository of type T as addressBook. This allows you to call GetObjectsQueryable of the parent class repository from the derived class addressBookRepository. The delegate function is applied as a predicate to the dataset of data context.[Learn More...]
(hits=14) This code snippet demonstrates how to invoke an IQueryable using fluent Api. The FluentAddressBook class is encapsulated within the AddressBookModule class. The AddressModule class may contain one or more Fluent classes. Each Fluent class can represent a domain of work. When I call the Query api of the fluentaddressbook class, the object is instantiated. It is important for you to remember that you can not call Apply() within a foreach. Entity Framework conflicts with the IEnumerable thread of the foreach and an error will be thrown.[Learn More...]
(hits=11) The Unit of Work and its repository objects do all the entity frame work of creating, updating, deleting, and querying data from the database. The fluentCustomerQuery contains a set of collections of different types which can be loaded by parameter passing or by generic expressions invokes. I will demonstrate, how to use an lambda expression invoke to apply to a collection in my next sample. The ICustomerQuery Query() is defined in the FluentCustomer concrete class. It returns a ICustomerQuery type because the fluentCustomerQuery class is derived from ICustomerQuery. You now can chain the methods of the fluentCustomerQuery class which has the WithAccountsReceivable, WithCustomerLedgers, ..etc methods. I use property getters to access the collections of type T from the fluentCustomerQuery instance.[Learn More...]
(hits=13) The Customer Interface defines all the chain methods in the FluentCustomer concrete class. In this use case, I only deal with a cashpayment. The invoice Module was used to create the account receiveable from an invoice. The modules represent the useage of the fluent api concrete classes. If I need to create an accounts receivable entry without an invoice than I would add the fluentaccountreceivable class to the module.[Learn More...]
(hits=10) Fluent API makes your code more discoverable and much more easier to read. The complexity of the code is insulated in the concrete classes. Chaining methods is a helpful technique for understanding complex processes. In my code sample, I demonstrate how to create a Customer account. The customer account will use a login password was a data link. First, we create the address book, next we associated an email with the address book, then we create the customer record, and link the customer location address to the customer. Fluent API makes communication of what the object methods do more natural. The ICustomerModule Interace only has one definition ICustomer Customer() which returns a fluentCustomer object. The self reference to ICustomer by the FluentCustomerModule allows chaining. FluentCustomerModule derives from ICustomerModule allowing chaining to Customer(). Once the fluentCustomer has been instantiated than we can access all of its chained methods.[Learn More...]
(hits=12) The disadvantage of Async all the way down with IQueryable is you use memory resource to build the collections. If the collections are large than your server resource is consumed.[Learn More...]
(hits=16) This snippet demonstrates how to use IQueryable to return data to a module method. IQueryable is an IEnumerable derived class meaning it allows you to foreach items in the collection. IQueryable does not retrieve data from the database until it is being enumerated. This allows you to retrieve large datasets and process the items in the dataset. IQueryable does not have an awaiter, so making it async is possible but not by design. To make it async you would convert the query to a list collection by type and return the list as AsQueryable.[Learn More...]
(hits=18) @""" are used to create one quote in json. A single @" is used to separate and start the c# code parsing to be inserted into the json string data.[Learn More...]
(hits=18) Newtonsoft JsonConvert.DeserializeObject is used to deserialize the json structure into the class objects. The JSON view in the debugger is helpful to know whether your json string has been formatted correctly.[Learn More...]
(hits=22) This code snippet demonstrates how to create a json string that can be deserialized into a class and class list encapsulated in the parent class. A purchaseOrderView contains a list of PurchaseOrderDetailViews. The unitOfWork will use the purchaseOrderView to create the purchase order and its details in the sql table. I demonstrate how to create a json string in c# in this demonstration. I bind information from the SupplierView, Company, and 5 item master objects into the json. The unit of work will do all the rollup calculations before writing to the database.[Learn More...]

Top 20 Microtheories

Top 5 Questions

Recent Questions