fluent

Builder pattern with nested objects

做~自己de王妃 提交于 2019-11-30 07:07:12
Hi I'm stuck with a problem. I want to implement the builder pattern to make creating my objects easier. The problem I face has to do with nested object. The object I would like to create has a list of other objects in it, and I don't really have an idea on how to tackle it. I want to be able to do the following (Simpler objects for example): Receipt RestaurantReceipt = new ReceiptBuilder() .withDate("value") .withName("value") .AddItem("value") .WithIngredients("value") .WithType("value") .AddItem("value") .WithIngredients("value") .WithType("value") .build(); Or something like: Receipt

laravel 4 eloquent eager load relation count

心不动则不痛 提交于 2019-11-30 00:08:03
问题 I have a complex Model with multiple defined relations. In this example I would want to count the Like model and create a property named likes so it can be returned from a REST service. Is it possible to eager load a model count into a dynamic property? $beat = Post::with( array( 'user', 'likes' => function($q){ $q->count(); } )) ->where('id', $id) ->first(); 回答1: Assuming you are having Post->hasMany->Like relationship and you have declared likes relationship as: class Post{ public function

FreeSql (四)实体特性 Fluent Api

老子叫甜甜 提交于 2019-11-29 20:29:36
FreeSql 提供使用 Fluent Api, 在外部配置实体的数据库特性,Fluent Api 的方法命名与特性名保持一致,如下: fsql.CodeFirst .ConfigEntity<TestFluenttb1>(a => { a.Name("xxdkdkdk1").SelectFilter("a.Id22 > 0"); a.Property(b => b.Id).Name("Id22").IsIdentity(true); a.Property(b => b.name).DbType("varchar(100)").IsNullable(true); }) .ConfigEntity<TestFluenttb2>(a => { a.Name("xxdkdkdk2").SelectFilter("a.Idx > 0"); a.Property(b => b.Id).Name("Id22").IsIdentity(true); a.Property(b => b.name).DbType("varchar(100)").IsNullable(true); }); //以下为实体类 class TestFluenttb1 { public int Id { get; set; } public string name { get; set; } = "defaultValue

How to change size of existing column using Entity Framework 6 Code First

旧时模样 提交于 2019-11-29 12:35:31
I have a POCO Plant that is mapped to a table dbo.Plant in my DB (SQL SERVER 2014). Some of the columns in the database has the data types nvarchar(max) NULL. I am trying to change the data type via EntityTypeConfiguration using the following code: Property(x => x.PCode).HasMaxLength(25); But, when adding the migration (add-migration name), the resulting Up()-method will not contain any changes for this column. However, if I also make it required like this: Property(x => x.PCode).HasMaxLength(25).IsRequired(); ..then the appropriate changes will be made in the Up()-method: AlterColumn("dbo

Redis嵌入式服务器,用于Java集成测试

耗尽温柔 提交于 2019-11-29 09:40:26
Maven依赖 Maven Central: < 依赖 > < groupId > com.github.kstyrc </ groupId > < artifactId > embedded-redis </ artifactId > < version > 0.6 </ version > </ dependency > 以前的版本(0.6之前): < repository > < id > clojars.org </ id > < url > http://clojars.org/repo </ url > </ repository > ... < 依赖 > < groupId > redis.embedded </ groupId > < artifactId > embedded-redis </ artifactId > < version > 0.5 </ version > </ dependency > 用法 运行RedisServer非常简单: RedisServer redisServer = new RedisServer(6379); redisServer 。开始(); //做一些工作 redisServer 。停(); 您还可以为RedisServer提供自己的可执行文件: // 1)给出显式文件(os-independent broken!)

Fluent NHibernate Generated AND Assigned ID Columns

≡放荡痞女 提交于 2019-11-29 03:46:00
I'm using Fluent NHibernate for my data-persistence in a web application. My problem... I have a base class that maps all entities with an ID property of type T (almost always an int or GUID) using GeneratedBy().Identity() On application start-up, I have a boot-strapper that checks and verifies the needed seed-data is populated. My problem is, some of the seed-data that is populated needs a specific ID. (IDs that would correspond to an enum or system user) Is there any way to force NHibernate to commit the record using the ID that I specify, rather than an auto-generated one? Any other commits

How to join table in fluent nhibernate

霸气de小男生 提交于 2019-11-28 19:23:19
how do we do this mapping but fluently? <class name="Person" table="People"> <id name="Id"> <generator class="identity"/> </id> <property name="Name" /> <join table="Addresses"> <key column="PersonId"/> <property name="Line1"/> <property name="Line2"/> <property name="City"/> <property name="Country"/> <property name="ZipCode"/> </join> </class> I know i can use 'References' but i don't need all the columns from the related table. i just need one property. gillyb What Paco said is not right. This can be done in Fluent NHibernate. I searched the web myself quite a while, couldn't find anyone

Fluent NHibernate Many-to-Many

雨燕双飞 提交于 2019-11-28 19:19:46
I am using Fluent NHibernate and having some issues getting a many to many relationship setup with one of my classes. It's probably a stupid mistake but I've been stuck for a little bit trying to get it working. Anyways, I have a couple classes that have Many-Many relationships. public class Person { public Person() { GroupsOwned = new List<Groups>(); } public virtual IList<Groups> GroupsOwned { get; set; } } public class Groups { public Groups() { Admins= new List<Person>(); } public virtual IList<Person> Admins{ get; set; } } With the mapping looking like this Person: ... HasManyToMany

How to select count with Laravel's fluent query builder?

有些话、适合烂在心里 提交于 2019-11-28 16:48:43
Here is my query using fluent query builder. $query = DB::table('category_issue') ->select('issues.*') ->where('category_id', '=', 1) ->join('issues', 'category_issue.issue_id', '=', 'issues.id') ->left_join('issue_subscriptions', 'issues.id', '=', 'issue_subscriptions.issue_id') ->group_by('issues.id') ->order_by(DB::raw('COUNT(issue_subscriptions.issue_id)'), 'desc') ->get(); As you can see, I am ordering by a count from the joined table. This is working fine. However, I want this count returned with my selections. Here is the my raw sequel query that works fine. Select issues.*, COUNT(issue

Set up caching on entities and relationships in Fluent Nhibernate?

懵懂的女人 提交于 2019-11-28 16:23:47
Does anyone have an example how to set up and what entities to cache in fluent nhibernate. Both using fluent mapping and auto mapping? And the same for entity relationships, both one-to-many and many-to-many? Dai Bok I have been working a a similar situation, where I just want to cache specific elements, and want these elements to be loaded once on start up, and kept in cache, until the application is shut down. This is a read only cache, and is used to populate a list of countries, so that a user can select their country from the list. I used fluentNhibernate Mappings, and defined Country my