-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRelationshipMap.cs
More file actions
40 lines (33 loc) · 1.15 KB
/
RelationshipMap.cs
File metadata and controls
40 lines (33 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using Poco.Sql.NetCore.Interfaces;
namespace Poco.Sql.NetCore
{
public class RelationshipMap<T, TTarget> : IRelationshipMap
{
private string _currentObject;
private string _foreignKey;
public Type RelatedObject { get; set; }
public RelationshipMap<T, TTarget> WithMany(Expression<Func<TTarget, ICollection<T>>> navigationPropertyExpression)
{
_currentObject = navigationPropertyExpression.Body.ToString();
_currentObject = _currentObject.Substring(_currentObject.LastIndexOf('.') + 1);
return this;
}
public RelationshipMap<T, TTarget> HasForeignKey<TKey>(Expression<Func<T, TKey>> foreignKeyExpression)
{
_foreignKey = foreignKeyExpression.Body.ToString();
_foreignKey = _foreignKey.Substring(_foreignKey.LastIndexOf('.') + 1);
return this;
}
public string GetForeignKey()
{
return _foreignKey;
}
public Type GetRelatedObjectType()
{
return RelatedObject;
}
}
}