fastmember

How can I use Fast Member to Bulk Copy data into a table with inconsistent column names?

亡梦爱人 提交于 2021-02-04 18:03:51
问题 I have a Person table with following column names: Id, Name, Dob I also have a poco as: public class Person { public int Id {get; set;} public string Name {get; set;} public string DateOfBirth {get; set;} } I am then trying: var people = new List<Person>(); ... // added a bunch of people using (var bcp = new SqlBulkCopy(sqlConnection, SqlBulkCopyOptions.TableLock, transaction)) using (var reader = ObjectReader.Create(people, "Id", "Name", "Dob")) { bcp.BulkCopyTimeout = 120; bcp.BatchSize = 0

SqlBulkCopy with ObjectReader - Failed to convert parameter value from a String to a Int32

社会主义新天地 提交于 2020-07-19 18:26:33
问题 I am using SqlBulkCopy (.NET) with ObjectReader (FastMember) to perform an import from XML based file. I have added the proper column mappings. At certain instances I get an error: Failed to convert parameter value from a String to a Int32. I'd like to understand how to 1. Trace the actual table column which has failed 2. Get the "current" on the ObjectReader sample code: using (ObjectReader reader = genericReader.GetReader()) { try { sbc.WriteToServer(reader); //sbc is SqlBulkCopy instance

SqlBulkCopy with ObjectReader - Failed to convert parameter value from a String to a Int32

点点圈 提交于 2020-07-19 18:25:51
问题 I am using SqlBulkCopy (.NET) with ObjectReader (FastMember) to perform an import from XML based file. I have added the proper column mappings. At certain instances I get an error: Failed to convert parameter value from a String to a Int32. I'd like to understand how to 1. Trace the actual table column which has failed 2. Get the "current" on the ObjectReader sample code: using (ObjectReader reader = genericReader.GetReader()) { try { sbc.WriteToServer(reader); //sbc is SqlBulkCopy instance

FastMember column order preservation

故事扮演 提交于 2019-12-22 18:10:00
问题 When using TypeAccessor.Create FastMember always seems to return a list of the columns in alphabetic sorted order. Is it possible to tell it to preserve the ordering of the columns in the class? for example: var testClass = new { B = "1", A = "2" }; will return column A then B from GetMembers, I'd like to get it to preserve the ordering of B then A if possible. 回答1: Looks like Evk is right and it can't really be done via the standard APIs. In the interest of completeness I'll leave this as

FastMember ObjectReader doesn't work with inherited interfaces

亡梦爱人 提交于 2019-12-22 10:38:41
问题 I get an interface as return from a library that I have no control over: public interface IA : IB { String A { get;} } public interface IB { String B { get;} } Now when I try to run this code, I get an exception: List<IA> list = library.Get(); IDataReader r = ObjectReader.Create(list, nameof(IA.A), nameof(IA.B)); while (r.Read()) { for (Int32 i = 0; i < r.FieldCount; i++) { //HERE ArgumentOutOfRangeException: Specified argument was out of the range of valid values.Parameter name: name Object

Assign value to Nullable<T> using FastMember

余生颓废 提交于 2019-12-10 10:05:29
问题 I have successfully assigned values to Properties and nested Properties using this function private static void AssignValueToProperty(ObjectAccessor accessor, object value, string propertyLambdaString) { var index = propertyLambdaString.IndexOf('.'); if (index == -1) { accessor[propertyLambdaString] = value; // problem above: throws Exception if assigning value to Nullable<T> } else { var property = propertyLambdaString.Substring(0, index); accessor = ObjectAccessor.Create(accessor[property])

FastMember column order preservation

故事扮演 提交于 2019-12-06 07:55:24
When using TypeAccessor.Create FastMember always seems to return a list of the columns in alphabetic sorted order. Is it possible to tell it to preserve the ordering of the columns in the class? for example: var testClass = new { B = "1", A = "2" }; will return column A then B from GetMembers, I'd like to get it to preserve the ordering of B then A if possible. Looks like Evk is right and it can't really be done via the standard APIs. In the interest of completeness I'll leave this as the answer. I created a fork of this project with column order option and added a PR to the original

How to get the Attribute data of a Member with FastMember

微笑、不失礼 提交于 2019-12-06 05:06:31
问题 using the FastMember library from NuGet, I am able to find all the members of a type that are decorated with a particular attribute, using this code: var accessor = TypeAccessor.Create(typeof (MyData)); var decoratedMembers = accessor.GetMembers().Where(x=>x.IsDefined(typeof(MyDecorationAttribute)); That's all very well and good, but I need to now be able to get the specific instance of MyDecorationAttribute for each of the members in decoratedMembers MemberSet and as far as I can see there

FastMember ObjectReader doesn't work with inherited interfaces

非 Y 不嫁゛ 提交于 2019-12-06 03:30:24
I get an interface as return from a library that I have no control over: public interface IA : IB { String A { get;} } public interface IB { String B { get;} } Now when I try to run this code, I get an exception: List<IA> list = library.Get(); IDataReader r = ObjectReader.Create(list, nameof(IA.A), nameof(IA.B)); while (r.Read()) { for (Int32 i = 0; i < r.FieldCount; i++) { //HERE ArgumentOutOfRangeException: Specified argument was out of the range of valid values.Parameter name: name Object o = r[i]; Console.Write(o + ","); } Console.WriteLine(); } It seems like it doesn't find the B property

How to get the Attribute data of a Member with FastMember

房东的猫 提交于 2019-12-04 11:25:23
using the FastMember library from NuGet, I am able to find all the members of a type that are decorated with a particular attribute, using this code: var accessor = TypeAccessor.Create(typeof (MyData)); var decoratedMembers = accessor.GetMembers().Where(x=>x.IsDefined(typeof(MyDecorationAttribute)); That's all very well and good, but I need to now be able to get the specific instance of MyDecorationAttribute for each of the members in decoratedMembers MemberSet and as far as I can see there isn't a way to do that. Am I missing something? Perhaps there's a different library that I should be