fluent-interface

How to combine conditions dynamically?

泄露秘密 提交于 2019-12-29 06:32:09
问题 This question is an enhancement to the already answered question How to apply multiple filter conditions (simultaneously) on a list? In the above mentioned question we have a method that applied AND operator on all the specifications. This is achieved by using LINQ All operator on the specifications. public static List<Product> GetProductsUisngAndFilters(List<Product> productList, List<Specification<Product>> productSpecifications) { return productList.Where(p => productSpecifications.All(ps

Unable to determine the principal end of an association - Entity Framework Model First

谁说胖子不能爱 提交于 2019-12-29 05:18:45
问题 I have created Entity Data Model in Visual Studio. Now I have file with SQL queries and C# classes generated from Model. Question: Classes are generated without annotations or code behind (Fluent API). Is it OK? I tried to run my application but exception was thrown: Unable to determine the principal end of an association between the types 'Runnection.Models.Address' and 'Runnection.Models.User'. The principal end of this association must be explicitly configured using either the relationship

Partial generic type inference possible in C#?

假装没事ソ 提交于 2019-12-27 12:05:08
问题 I am working on rewriting my fluent interface for my IoC class library, and when I refactored some code in order to share some common functionality through a base class, I hit upon a snag. Note : This is something I want to do, not something I have to do. If I have to make do with a different syntax, I will, but if anyone has an idea on how to make my code compile the way I want it, it would be most welcome. I want some extension methods to be available for a specific base-class, and these

Method chaining - why is it a good practice, or not?

限于喜欢 提交于 2019-12-27 10:35:30
问题 Method chaining is the practice of object methods returning the object itself in order for the result to be called for another method. Like this: participant.addSchedule(events[1]).addSchedule(events[2]).setStatus('attending').save() This seems to be considered a good practice, since it produces readable code, or a "fluent interface". However, to me it instead seems to break the object calling notation implied by the object orientation itself - the resulting code does not represent performing

Method chaining - why is it a good practice, or not?

Deadly 提交于 2019-12-27 10:30:14
问题 Method chaining is the practice of object methods returning the object itself in order for the result to be called for another method. Like this: participant.addSchedule(events[1]).addSchedule(events[2]).setStatus('attending').save() This seems to be considered a good practice, since it produces readable code, or a "fluent interface". However, to me it instead seems to break the object calling notation implied by the object orientation itself - the resulting code does not represent performing

Create a base fluent ordered constructor

白昼怎懂夜的黑 提交于 2019-12-27 03:33:08
问题 EDIT: Ok, seem example is unuseful... I have an ordered fluent constructor that is common to many object (all have tha same properties). Is there a way to put all the code in the same base factory class and have only the final costructor in the derived factory? I use constructor like this .InitCreation() .WithID() .WithPoperty1() .Create() where only the Create() make the new object and ID is a mandatory field. Generics seem me to need rewriting all methods in all factory, instead i want to

Progressing fluent interfaces how can I hide all methods but one at the start?

百般思念 提交于 2019-12-25 08:13:38
问题 Trying to create a simple noddy example so that I can build my next project using fluent interfaces. I need to provide the user of my dll with an intuitive step by step way of building a class. Question. I would like the user only to see Initialise when the first start then step1 then step2 and then end?How can I do it? This is my attempt which As soon as you put the "." you see everything,then they hide. class Program { static void Main(string[] args) { IEnd builder = new StepBuilder()

How do I cascade deletes into a link table using the EF4 fluent API?

久未见 提交于 2019-12-23 18:23:22
问题 I have two tables in an existing (MSSQL 2008 R2) database that are related by a link table. The two tables are "Plan" and "Tips". The link table is "PlanTipLinks". Plans can have many tips, and tips can be associated with multiple plans (i.e. it's a many-to-many relationship). In the application, I only care about the "Plan.Tips" relationship. I don't need the Tip.Plans inverse relationship. The foreign key references in the link table cannot be null. I'm using the following fluent API code

How to ensure the sequence of methods in fluent API?

蹲街弑〆低调 提交于 2019-12-22 10:39:34
问题 I want to create fluent interface for some of my classes that I am building as part of a framework. I have created the methods and I am able to successfully chain methods. Now I want to ensure that I can handle the improper sequence of method calls. The thing I am doing is something like CreateWorkflow -> OpenConfiguration -> ChangeUserName In the above scenario it wouldn't make sense if ChangeUserName was called first because it is dependent on OpenConfiguration. I am confused whether I am

EF Code First - Fluent API (WithRequiredDependent and WithRequiredPrincipal)

巧了我就是萌 提交于 2019-12-22 04:33:21
问题 I have the following class: public class User { public Guid Id { get; set; } public string Name { get; set; } public Couple Couple { get; set; } } public class Couple { public Guid Id { get; set; } public User Groom { get; set; } public User Bride { get; set; } } Important points: Bride and Groom properties are required One-to-one relationship In the User class, it is Couple required DbContext in OnModelCreating modelBuilder.Entity<User>().HasRequired(u => u.Couple).WithRequiredPrincipal();