将LDAP数据映射到.NET类(LINQ)
为了构建LINQ到LDAP模型,我一直在使用几种不同的TUT。我已经差不多完成了,但是我在尝试绑定返回给类的数据时遇到了一些问题 我通过为类的属性(即数据库字段的实际名称)指定自定义属性来完成相反的部分 下面是该类的示例以及自定义属性(不包括将LDAP数据映射到.NET类(LINQ),.net,linq,ldap,linq-to-ldap,.net,Linq,Ldap,Linq To Ldap,为了构建LINQ到LDAP模型,我一直在使用几种不同的TUT。我已经差不多完成了,但是我在尝试绑定返回给类的数据时遇到了一些问题 我通过为类的属性(即数据库字段的实际名称)指定自定义属性来完成相反的部分 下面是该类的示例以及自定义属性(不包括DirectorySchemaAttribute和DirectoryRootAttribute实现…这些部分工作正常): 谢谢, Chris您知道“LINQ到Active Directory”吗??请在上查看 这可能是一个很好的起点 马克不错。我看到的图坦卡
DirectorySchemaAttribute
和DirectoryRootAttribute
实现…这些部分工作正常):
谢谢,
Chris您知道“LINQ到Active Directory”吗??请在上查看
这可能是一个很好的起点
马克不错。我看到的图坦卡蒙实际上是由发布这些课程的同一个人写的。现在拥有所有的代码是很有帮助的。在支持LDAP(而不是AD)方面仍然有一些困难,但您的帖子解决了我最初的问题。谢谢
[DirectorySchema("C4User"), DirectoryRoot("o=c4, ou=users")]
class User
{
[DirectoryAttribute("cn")]
public string Username { get; set; }
[DirectoryAttribute("userpassword")]
public string Password { get; set; }
[DirectoryAttribute("C4-Parent")]
public string Parent { get; set; }
}
/// <summary>
/// Specifies the underlying attribute to query for in the directory.
/// </summary>
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
public class DirectoryAttributeAttribute : Attribute
{
private string attribute;
private DirectoryAttributeType type;
/// <summary>
/// Creates a new attribute binding attribute for a entity class field or property.
/// </summary>
/// <param name="attribute">Name of the attribute to query for.</param>
public DirectoryAttributeAttribute(string attribute)
{
this.attribute = attribute;
this.type = DirectoryAttributeType.Ldap;
}
/// <summary>
/// Creates a new attribute binding attribute for a entity class field or property.
/// </summary>
/// <param name="attribute">Name of the attribute to query for.</param>
/// <param name="type">Type of the underlying query source to get the attribute from.</param>
public DirectoryAttributeAttribute(string attribute, DirectoryAttributeType type)
{
this.attribute = attribute;
this.type = type;
}
/// <summary>
/// Name of the attribute to query for.
/// </summary>
public string Attribute
{
get { return attribute; }
set { attribute = value; }
}
/// <summary>
/// Type of the underlying query source to get the attribute from.
/// </summary>
public DirectoryAttributeType Type
{
get { return type; }
set { type = value; }
}
}
private string GetFieldName(System.Reflection.MemberInfo member)
{
DirectoryAttributeAttribute[] da = member.GetCustomAttributes(typeof(DirectoryAttributeAttribute), false) as DirectoryAttributeAttribute[];
if (da != null && da.Length != 0)
{
if (da[0].Type == DirectoryAttributeType.ActiveDs)
throw new InvalidOperationException("Can't execute query filters for IADs* properties.");
else
return da[0].Attribute;
}
else
return member.Name;
}