fluent-interface

OOP problem: Extending a class, override functions and jQuery-like syntax

寵の児 提交于 2019-12-06 01:43:13
I have an OOP related problem with Flash, actionscript 3. It's a personal project, and I am looking for a design pattern or workaround for this problem, and my goal is to learn new things. I have created a class called Chain. I created this util-class to make delayed function calling easy. You can make a chain of functions, by adding them with a delay in milliseconds. This chain can be executed multiple times, even in reversed order. This class has functions which returns itself. That makes it possible to have a jQuery styled syntax like this: var chain:Chain = new Chain(); chain.wait(100).add

Fluent Interfaces Implementation

僤鯓⒐⒋嵵緔 提交于 2019-12-05 22:55:16
In order to make my code more organized i have decided to use fluent interfaces; However by reading the available tutorials i have found many ways to implement such fluency, among them i found a topic who says that to create Fluent Interface we should make use of Interfaces , but he did not provided any good details in order to achieve it. Here is how i implement Fluent API Code public class Person { public string Name { get; private set; } public int Age { get; private set; } public static Person CreateNew() { return new Person(); } public Person WithName(string name) { Name = name; return

EF Code First - Fluent API (WithRequiredDependent and WithRequiredPrincipal)

混江龙づ霸主 提交于 2019-12-05 03:38:14
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(); modelBuilder.Entity<Couple>().HasRequired(u => u.Bride).WithRequiredDependent(); modelBuilder.Entity

Entity Framework Code First - One-to-Many with a join/link table

£可爱£侵袭症+ 提交于 2019-12-05 01:39:19
问题 Is it possible to create a One-to-Many relationship with Code First that uses a link/join table between them? public class Foo { public int FooId { get; set; } // ... public int? BarId { get; set; } public virtual Bar Bar { get; set; } } public class Bar { public int BarId { get; set; } // ... public virtual ICollection<Foo> Foos { get; set; } } I want this to map as follows: TABLE Foo FooId INT PRIMARY KEY ... TABLE Bar BarId INT PRIMARY KEY TABLE FooBar FooId INT PRIMARY KEY / FOREIGN KEY

Implementing conditional in a fluent interface

穿精又带淫゛_ 提交于 2019-12-04 23:47:15
问题 I've been trying to implement a fluent interface for a set of rules in my system. What I am trying to accomplish is this TicketRules .RequireValidation() .When(quartType => quartType == QuartType.Before).TotalMilageIs(64) .When(quartType => quartType == QuartType.After).TotalMilageIs(128); However, I have trouble implementing the When conditional how I intended to be. Currently, I need to call When() twice like in this snippet: rules.When(param => param.Remarque == "Test").TotalMilageIs(100);

Does Entity Framework Code First allow for fluent mappings in separate files?

雨燕双飞 提交于 2019-12-04 17:42:11
问题 I am developing a rather large database schema using Entity Framework Code First. I prefer the Fluent API over the Data Annotations approach, as it leaves my domain objects as simple POCOs. In order to use Fluent API, I have to override OnModelCreating in the class that inherits from DbContext. I don't like that all mappings for all of my entities are in this one method. I have used things like FluentNHibernate before, where each entity has it's own mapping class. Does EF have anything

Ignore Properties in OnModelCreating

怎甘沉沦 提交于 2019-12-04 17:12:35
I'm attempting to use Bounded (Db) Contexts in Entity Framework 5.0, and I'm having problems excluding a property from one of the classes included in a specific context. Here is the information (I'll shorten for brevity) BaseContext.cs public class BaseContext<TContext> : DbContext where TContext : DbContext { static BaseContext() { Database.SetInitializer<TContext>(null); } protected BaseContext() : base("name=Development") { } } IContext.cs public interface IContext : IDisposable { int SaveChanges(); void SetModified(object entity); void SetAdded(object entity); } ISuiteContext.cs public

Entity Framework Code First - Foreign Key to non primary key field

拟墨画扇 提交于 2019-12-04 07:22:16
I have two tables that look like this: dbo.ReviewType ReviewTypeId INT PRIMARY KEY ShortName CHAR(1) - Unique Index Description dbo.Review ReviewId INT PRIMARY KEY ReviewType_ShortName CHAR(1) - FK to ReviewType ... A Review always has a ReviewType. A ReviewType can be associated with many reviews. I'm having trouble mapping this in Entity Framework using the Code First Fluent API. It seems like it does not like me using a foreign key that doesn't map to the Primary Key. I'm using a foreign key to a Unique Constraint/Index instead of to the Primary Key. How can I map this properly in Entity

Unable to send embedded image in email using FluentEmail

假装没事ソ 提交于 2019-12-04 05:29:10
I'm using FluentEmail in ASP.NET core 2.0 class library which will be sending the Email notification. Below is the sample code I have tried till now: using FluentEmail.Core; using FluentEmail.Razor; using FluentEmail.Smtp; using System; using System.IO; using System.Net.Mail; using System.Net.Mime; namespace FluentEmail { public class EmailNotification : IEmailNotification { public bool SendEmailNotification() { try { //Setup Default sender befault sending the email. SmtpClient smtpClient = new SmtpClient { Host = "smtp.office365.com", Port = 587, EnableSsl = true, Credentials = new System.Net

Effects of method chaining

自闭症网瘾萝莉.ら 提交于 2019-12-04 04:30:58
I know the benefits of chaining within PHP but lets say we have this following situation $Mail = new MailClass("mail") ->SetFrom("X") ->SetTo("X") ->SetSubject("X") ->AddRecipient("X") ->AddRecipient("X") ->AddRecipient("X") ->AddRecipient("X") ->AddRecipient("X") ->AddRecipient("X") ->Send(); Are there any issues with returning and reusing the object over and over again, issues such as speed or failure to follow best Practises Also a good read on this if your new to Fluent-Interface's: Martin Fowler on Fluent-Interfaces I Fully understand that it doesn't have to be programmed this way, and