Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 103811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:10:58+00:00 2026-05-11T01:10:58+00:00

I have a fixed-length data file need to persistence into database. I use a

  • 0

I have a fixed-length data file need to persistence into database. I use a XML file to define the length for the fields and use a list of FieldItem class to store the data.

   class FieldItem    {         public string ObjectName {get; set;}         public string ObjectProperty {get; set;}         public string ObjectValue {get; set;}          public FieldItem()        {        }    } 

So the FieldItem will look like

var fieldItem = new FieldItem                 {                    ObjectName = 'Company',                    ObjectProperty = 'Name',                    ObjectValue = 'ABC Corp.'                 } 

After get the list of FieldItem, I will do refection to create Company and other domain objects to save them into database.

But before they are saved into database, I have some business rules needed to be applied to validate the data line. My data line will look like:

var fieldItemList = new List<FieldItem>(){                 new FieldItem {                     ObjectName='Company',                     ObjectProperty = 'Name',                     ObjectValue = 'ABC'                 }                  new FieldItem{                     ObjectName = 'Product',                     ObjectProperty = 'ProductCode',                     ObjectValue ='XYZ0123'                      new FieldItem{                     ObjectName = 'Product',                     ObjectProperty = 'ProductName',                     ObjectValue ='Christmas Tree'                        }                      // other FieldItem objects...              } 

For example, my rule is to check if the company == ‘ABC’ and ProductCode == ‘XYZ0123’. Those rules are created by users and stored as a string in the database. What I am doing right now is to use Microsoft’s System.Linq.Dynamic to evaluate the rule, such as

string validationRule = ' (ObjectName == \'Company\' And ObjectProperty=\'CompanyName\' And ObjectValue = \'ABC Corp.\') And (ObjectName == \'Product\' And ObjectProperty=\'ProductCode\' And ObjectValue = \'XYZ0123\') ';    var query = fieldItemList.AsQuerable().Where(validationRule); 

then check if it has one row return to tell if that data row has passed the rule or not. Obviously, it is too verbose. Do you have any better suggestion? What should I do if I only like my rule expression like: ‘Company.CompanyName = ‘ABC Corp.’ and Product.ProductCode = ‘XYZ001”?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T01:10:58+00:00Added an answer on May 11, 2026 at 1:10 am

    RE: ‘What should I do if I only like my rule expression like: ‘Company.CompanyName = ‘ABC Corp’ and Product.ProductCode = ‘XYZ001”?

    Map this user-friendly query: ‘Company.CompanyName = ‘ABC Corp’ AND Product.ProductCode = ‘XYZ001” to something that is friendly to your data structure(FieldItem):

    ‘ObjectName = ‘Company’ AND ObjectProperty = ‘CompanyName’ AND ObjectValue = ‘ABC Corp’ OR ObjectName = ‘Product’ AND ObjectProperty = ‘ProductCode’ AND ObjectValue = ‘XYZ001”

    How to know if the user’s rules passed the rules or not? Count the number of conditions, if it matches the count of results of fieldItemList.AsQueryable().Where(itemFieldFriendlyQuery), then the data line is valid based on user’s rules.


    some rudimentary mapper(use regular expression or roll your own parser to make the following code truly valid):

    public Form3() {     InitializeComponent();      string userFriendlyQuery = 'Company.CompanyName = 'ABC Corp' AND Product.ProductCode = 'XYZ001'';      string[] queryConditions = userFriendlyQuery.Split(new string[]{' AND '},StringSplitOptions.None);     int conditionsCount = queryConditions.Length;      string itemFieldFriendlyQuery = string.Join(' OR ',          queryConditions.Select(condition =>             {                 var conditionA = condition.Split(new string[] { ' = ' }, StringSplitOptions.None);                  var left = conditionA[0];                 var leftA = left.Split('.');                  string objectName = leftA[0];                 string objectProperty = leftA[1];                  var right = conditionA[1];                  return string.Format('ObjectName = '{0}' AND ObjectProperty = '{1}' AND ObjectValue = {2}',                     objectName, objectProperty, right);             }         ).ToArray());        MessageBox.Show(itemFieldFriendlyQuery);      // outputs: 'ObjectName = 'Company' AND ObjectProperty = 'CompanyName' AND ObjectValue = 'ABC Corp' OR ObjectName = 'Product' AND ObjectProperty = 'ProductCode' AND ObjectValue = 'XYZ001''       bool isValid = fieldItemList.AsQueryable().Where(itemFieldFriendlyQuery).Count() == conditionsCount;       MessageBox.Show(isValid.ToString()); }    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 68k
  • Answers 68k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Some of the other answers didn't work for my version… May 11, 2026 at 12:06 pm
  • added an answer Lucky for you I built a sudoku solver myself not… May 11, 2026 at 12:06 pm
  • added an answer I am going refer to the C# example in the… May 11, 2026 at 12:06 pm

Related Questions

I have a fixed-length data file need to persistence into database. I use a
I have a fixed width DIV containing a table with many columns, and need
I have a container div with a fixed width and height , with overflow:
I have a really simple search form with the following Label (Search) Textbox (fixed
If I have an array of a fixed size depending on how it is
I have an application that has a primary layout of portrait (it is fixed
I have an input[type=radio] element inside a block container of fixed width. The supporting
I've seen a few fixes for allowing PNG images to have transparency in Internet
I have a web-service that I will be deploying to dev, staging and production.
I have a .Net desktop application with a TreeView as one of the UI

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.